It's been tough nailing down the optimal time, but right now what works best is taking 300ug of melatonin at 10:20pm and falling asleep at 11:50.
In the past I tried various different times ranging from 6:30pm to 9:00pm. Even taking it at a suboptimal time is better than not taking it at all.
There are also a few other things I do to keep my sleep schedule on track:
1) I heavily use bluelight filters on my computers and phone in the evening. Redshift/gammastep on Linux gives me full control.
2) I have low blue light lights which I use in the evening [0], then I switch to fully red bulbs in the hour before going to sleep.
3) I have a super bright daylight LED lamp which turns on automatically at 8:30am, a few minutes before I wake up. This is my solution to automate light therapy [1].
All of this combined lets me function mostly like a normal person. Hope some of that helps.
I can't find the link right now, but I recall reading from a credible source that melatonin works two ways (from memory so may not be completely accurate):
* Adjusting diurnal rhythm (e.g. adjust a skewed sleeping schedule, jet lag). This works in lower doses over longer periods of time. So if you want to be less of a night owl, you may take 0.1-0.3 mg in the afternoon.
* Hypnotic - immediately making you more prone to fall asleep. This one is less well understood and dosages vary per person but it seems like 0.3-3 mg shortly before bed time is optimal. It also won't work on it's own like stilnoct or whatnot, so limiting light exposure, and all the other usuals, still apply.
I also find it frustrating how much more expensive and less available lower dosages are. From someone who also does bits and nibbles of 3mg pills.
For me, when I take melatonin, I feel sleepy within about half an hour, and if I don't go to sleep then, the sleepiness will pass and the melatonin would be ineffective. So I take it about half an hour before bedtime so that I am in bed within the effectiveness window.
In the past I tried various different times ranging from 6:30pm to 9:00pm. Even taking it at a suboptimal time is better than not taking it at all.
There are also a few other things I do to keep my sleep schedule on track:
1) I heavily use bluelight filters on my computers and phone in the evening. Redshift/gammastep on Linux gives me full control.
2) I have low blue light lights which I use in the evening [0], then I switch to fully red bulbs in the hour before going to sleep.
3) I have a super bright daylight LED lamp which turns on automatically at 8:30am, a few minutes before I wake up. This is my solution to automate light therapy [1].
All of this combined lets me function mostly like a normal person. Hope some of that helps.
[0]: https://www.amazon.com/s?k=2000k+bulb
[1]: https://en.wikipedia.org/wiki/Light_therapy