07.02.2018, 12:23
What Bolex meant is utilizing MySQL to do the job for you. But you can also use this genius formula:
jday is the julian day (so the number of days passed since the beginning of unix), the lower part adds the day-time in seconds (which is the easiest part, as you can see).
It's working perfectly fine, respecting leap years etc.
It can be shortened a lot but you can do that yourself if you want.
Код:
datetime_to_unix(year, month, day, hour, minute, second) { new jday = 367 * year - 7 * (year + (month + 9) / 12) / 4 - 3 * ((year + (month - 9) / 7) / 100 + 1) / 4 + 275 * month / 9 + day + 1721029 - 2440588; return jday * 86400 + hour * 3600 + minute * 60 + second; }
It's working perfectly fine, respecting leap years etc.
It can be shortened a lot but you can do that yourself if you want.