Anyone need unix timestamps or pretty dates (the calendar kind)?
true
Junior Member
I was bored again today - so I decided to write a netlinx time/date to unix timestamp (and back) converter and a formatted date function similar to php's date() to make use of a timestamp. If you're interfacing with devices that want a unix timestamp, or want prettier / different dates for touchpanels, this code might help.
For instance, this code:
Unix timestamps are provided adjusted to the local timezone (ala clkmgr or a specified offset) with unixtime(LDATE, TIME) or unixtime_now(), and not adjusted (UTC-based) with unixtime_utc(LDATE, TIME). DST via clkmgr is only barely supported - when it's on, it applies a +1hr offset... anyone have better documentation for the clkmgr_ functions? Right now my fmt_date() isn't timezone-aware so it wants a UTC based time, so don't get too confused with the example above
Even if you don't care about unix timestamps, having something more than the built-in date types on panels that's easily adjustable might appeal to you. Yay ordinal suffixes!
I've also got functions to convert unix timestamps (say, from a remote webserver or device) back into AMX-compatible DATE/LDATE/TIME strings - unixtime_to_netlinx_ldate(), etc. if you have these date types and would prefer to work with AMX date/time strings.
Since I'm working solely residential now, I wrote (not on company time, sigh) a no-ip sync module and I may also write a dyndns-protocol compatible module. Anyone have use for these?
edit: 10000th post in this forum
For instance, this code:
send_string 0, fmt_date('\T\h\e \d\a\t\e \i\s l, F jS Y g:ia \D\a\y #z', unixtime_utc(LDATE, TIME))
sends to the console:
(0000752985) The date is Saturday, March 27th 2010 9:12pm Day #85
Unix timestamps are provided adjusted to the local timezone (ala clkmgr or a specified offset) with unixtime(LDATE, TIME) or unixtime_now(), and not adjusted (UTC-based) with unixtime_utc(LDATE, TIME). DST via clkmgr is only barely supported - when it's on, it applies a +1hr offset... anyone have better documentation for the clkmgr_ functions? Right now my fmt_date() isn't timezone-aware so it wants a UTC based time, so don't get too confused with the example above
I've also got functions to convert unix timestamps (say, from a remote webserver or device) back into AMX-compatible DATE/LDATE/TIME strings - unixtime_to_netlinx_ldate(), etc. if you have these date types and would prefer to work with AMX date/time strings.
Since I'm working solely residential now, I wrote (not on company time, sigh) a no-ip sync module and I may also write a dyndns-protocol compatible module. Anyone have use for these?
edit: 10000th post in this forum
Comments
-
If anyone indeed is interested, I've added this as part of the Netlinx Common Libraries.
-
not working?
hi,
timestamp -> date is not working when is a leapyear...
---
Error on line 558 and 559: in the "unixtime_to_raw_values" Function
if (unixtime_year_is_leapyear(yr)) {
//w2 = UNIXTIME_SECONDS_PER_DAY
>do not overwrite this stack_var!
//w = w - w2
w=w - UNIXTIME_SECONDS_PER_DAY //do this way
} -
thanks
for this... is very useful... for me -
Has anyone tried this module to get Unix time? I am getting results that seem to indicate its an hour off (3600 seconds), so I'm guessing DST is throwing things off. I've compared to unixtime calculators online in my time zone, and to get them to match I have to add 3600 seconds.
The underlying OS has all the time/date functions you could ask for. Too bad there is no exec() function.
Paul
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums