Convert Date Time to UTC

sandeep24
Tera Guru

Hi,

ON NEW FORM when user selects DATETIME field(ex: start date), I need to convert it to UTC time in Client Script(or using GlideAjax)

 

Thanks

1 ACCEPTED SOLUTION

Hi,

Perhaps it's doing that because it's not saved to the database at that time. I see why you were specifically mentioning "new" record in your post. I didn't see that before.

With that said, you should be able to still use GlideAjax, onChange client script, for example, take that value from that field, send it to your script include and use that to "set the display value" of a GlideDateTime object, so not set the value, but set the display value of a GlideDateTime object.

Then...get the value, send it back to your client for use in your alert or whatever you need to do.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

12 REPLIES 12

Hello,

I've linked you right to the documentation on setting the display value for a GlideDateTime object, please take a moment and use that link for example.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Below is working

setDisplayValueInternal(String value)

Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the current user's time zone.


CODE:
var gdt = new GlideDateTime();
gdt.setDisplayValueInternal("2022-04-29 15:54:26"); //uses current user session time zone (ITS)
gs.info(gdt.getValue());

Output: 

2022-04-29 10:24:04

Thank you Allen and Robbie for you help

Robbie
Kilo Patron
Kilo Patron

Hi Sandeep,

Glad you got to the desired solution. Some great help and advice from Allen and good to see leveraged the getValue() method I proposed.

To help others, can you mark my initial response as correct and/or helpful.

Thanks, Robbie