TimeAndDate Module

I created a nifty little module that will retrieve the time and date information of any given location using Google’s Timezone API (given that it is supported by Google’s timezone API).

You can find it here.

Current API:

module.getTime(latitude, longitude[, format12 = false]): returns a table with time and date information, provided that latitude and longitude are valid coordinates which are supported by Google’s timezone API. ‘format12’ is optional. If true, then the hours will be provided in 12 hour format and the period field in the data table will contain either “am” or “pm”. The table that it returns contains:
[ul]

[li]seconds (current time, integer)[/li]
[li]minutes (current time, integer)[/li]
[li]hours (current time, integer)[/li]
[li]period (am/pm, set to an empty string if format12 is false or not provided)[/li]
[li]month (integer)[/li]
[li]year (integer)[/li]
[li]yearDay (how many days into the year, integer)[/li]
[li]monthDay (how many days into the month, integer)[/li]
[li]weekDay (how many days into the week. Monday = 1, Sunday = 7, integer)[/li]
[li]monthName (current month name, string)[/li]
[li]dayName (current day name, string)[/li]
[/ul]

Some notes:

[ul]
[li]Requires HttpService to retrieve data from the Google timezone API[/li]
[li]Will only be accurate to about ±5 minutes because of unsynchronized unix epoch times for UTC for Google and Roblox servers.[/li]
[/ul]

Questions, bug reports or suggestions, post here.

2 Likes

Cool module. I have question though. Why the inaccuracy? I don’t understand why that needs to be

There isn’t any (in theory - blame timezones). If you use UTC/GMT your time will be constant no matter where you are.

That’s really neat. I published a Date & Time module the other day that includes a big number of formatting options and also operations on the times. You could definitely borrow some of that to make this a more fun library!

It’s a shame there’s no real benefit to knowing the time in different places in the world :confused: At least you could get accurate daylight-savings adjusted time for a particular timezone.

Too be honest, I have absolutely no idea why there are inaccuracies. When I check my local time using the coordinates for where I live, it’s the same time as my alarm clock, but 1 minute faster than the time that my cell service provides me, and 3 minutes slower than the time on my PC that defaulted with my timezone.

The time differences are calculated from the unix time for UTC.