- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 05:39 PM
Hi All,
Is it possible to get the current datetime in UTC?
I have a scenario where I have to find the difference a datetime value from my custom table field(this value is in UTC) and the current datetime. i want to make sure that the current datetime is also in UTC so that no matter what the timezone of the system is, the difference i get is always between two datetime values in UTC.
I am planning to use GlideDateTime subtract(GlideDateTime start, GlideDateTime end) to get the difference.
thanks,
Neha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 06:32 PM
Hi Neha,
GlideDateTime and the GlideDateTime.subtract don't need to worry about timezones. All GlideDateTimes are internally stored as an integer representing the number of milliseconds since January 1, 1970 00:00:00 GMT. So when you use the GlideDateTime subtract function, Time Zones are already factored out. To get the current time in GlideDateTime, all you need is:
var gdt1 = new GlideDateTime(); // Current DateTime
var duration = GlideDateTime.subtract(gdt1, gdt2); // Assuming gdt2 is another GlideDateTime
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 06:00 PM
Try this...
var d = new Date();
var n = d.getTime();
alert(n)
RM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 09:32 AM
Thanks Russell, i am gonna try it and see if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 06:32 PM
Hi Neha,
GlideDateTime and the GlideDateTime.subtract don't need to worry about timezones. All GlideDateTimes are internally stored as an integer representing the number of milliseconds since January 1, 1970 00:00:00 GMT. So when you use the GlideDateTime subtract function, Time Zones are already factored out. To get the current time in GlideDateTime, all you need is:
var gdt1 = new GlideDateTime(); // Current DateTime
var duration = GlideDateTime.subtract(gdt1, gdt2); // Assuming gdt2 is another GlideDateTime
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 11:20 AM
Thanks for you response Travis, this worked
-Neha