To file for divorce in California, either you or your spouse has to have lived in California for the past 6 months and in your current California county for the past 3 months.
This is known as meeting the residency requirement. You can file for divorce in any county where one of you meets the residency requirement. Check which county you could file in if you're not sure.
To file for a legal separation, one of you must live in California. There is no requirement for how long that person must have lived in California.