UTCOffset
Returns the offset from UTC of the current device clock
Average rating: 3.8 (49 votes) Log in to vote
Jeremy Bante https://github.com/jbante/ |
List (
UTCOffset;
Get ( CurrentTimestamp );
GetAsTimestamp ( Get ( UTCmSecs ) / 1000 + GetUTCOffset )
)
05-18-2012 17:04:31
05-18-2012 17:04:31.062
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Returns the offset from UTC of the current device clock. This can be used for establishing the time zone a device is operating in.
Comments
Jesse Barnum, Atlanta, GA Apr 3, 2014 |
||
Thanks, this was really handy. One improvement: Using floor is better than using round, otherwise you'll be off by one second 50% of the time. |
||
Jeremy, USA Apr 3, 2014 |
||
Sounds reasonable enough. Done! | ||
Matt Larson Oct 13, 2015 |
||
Not sure if I'm doing something wrong here… I'm getting results that are seemingly 1 hour off. I'm in Central Standard Time (CST). Get(CurrentTimestamp) = 10/13/2015 9:00:00 PM UTC Timestamp = 10/14/2015 3:00:00 AM Difference = 6 hours But, when I apply the UTCOffset CF to the UTC timestamp, it brings it back to 10 PM, which is only 5 hours difference. Is there a daylight savings issue going on or something? |
||
Matt Larson Oct 16, 2015 |
||
Nevermind… I was looking at a map that told me to subtract 6 hours when apparently the correct UTC is 5 hours for me. Daylight savings issue or something. Your custom function is working correctly, and perfectly for me, now that I solved my root problem! | ||
manda, Slovenia May 29, 2017 |
||
Anybody located East of UTC will not get the difference in seconds, but the Timestamp of that difference. Change the formula to: GetAsNumber ( Get ( CurrentTimestamp ) ) - Floor ( Get ( CurrentTimeUTCMilliseconds ) / 1000 ) |
||
Jeremy, Earth May 30, 2017 |
||
The point of the function is not that it's result is a number or a timestamp, but that the result of adding and subtracting it with a timestamp results in a meaningful timestamp. I don't care if UTCOffset is a number or timestamp as long as Timestamp ( ... ) ± UTCOffset is a timestamp in typical use. | ||
Paul, Peak 14 LLC Mar 10, 2021 |
||
This is a great custom function, however I'm getting some odd behavior with web direct and browsers. Depending on the browser, I get different offsets that vary by a few min. For example, I get the following results in MST (UTC-7): FileMaker App: -7:00:00 Chrome: -6:59:55 Firefox: -6:59:54 I'm sure this is because how the browser handles Get(CurrentTimeStamp), but I'm not sure if the best solution is to just round it to the nearest hour or not. |
||
Paul, Peak 14 LLC Mar 11, 2021 |
||
In case anyone reads this later, this is what I ended up doing to solved for the different in timestamps with browsers. Adds some complexity, but works with every browser I've tried: Let ( [ ~tsLocal = Get ( CurrentTimestamp ); ~tsUTC = GetAsTimestamp ( Get ( CurrentTimeUTCMilliseconds ) / 1000 ) ]; GetAsTime ( Timestamp ( Date ( Month ( ~tsLocal ) ; Day ( ~tsLocal ) ; Year ( ~tsLocal ) ) ; Time ( Hour ( ~tsLocal ) ; 0 ; 0 ) ) - Timestamp ( Date ( Month ( ~tsUTC ) ; Day ( ~tsUTC ) ; Year ( ~tsUTC ) ) ; Time ( Hour ( ~tsUTC ) ; 0 ; 0 ) ) ) ) |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.