Set current date time using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 09:38 PM - edited 06-03-2024 09:42 PM
Hi,
We have a scenario when state changes to Assigned, the assigned date field should get update with current date time.
I am trying to on change client script with below script but it has update with incorrect format.
Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 03:48 AM
Hello Divya,
Regarding the time zone. First, you have to check your instance system timezone from "Basic Configuration".
Then change this script according to your timezone. For this script the time zone is "Ameria/New_York".
var today_date= new Date();
var easternTime = today_date.toLocaleString("en-US", {timeZone: "America/New_York"});
Try this and let me know if approach will work or not.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 06:53 AM
HI MIhir,
I have written the below code , but its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 10:37 PM
Hello Divya,
Could you explain please, Do you have a problem with the date format or an incorrect date value?
When I tried in the background script it returned: 4 Jun
var today_date = new Date();
gs.info(today_date);
Tue Jun 04 2024 22:27:07 GMT-0700 (PDT)
When I tried in the Client script it returned: 5 Jun
var today_date = new Date();
alert(today_date);
Wed Jun 05 2024 11:00:24 GMT+0530 (India Standard Time)
I don't know how it is returned on a different date.
Could you please explain to me, What is your exact problem with the screen short of the date?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 10:49 PM
Hello @DivyaNarayG
If necessary, you can explicitly specify the time zone you want to use with the new Date() function by providing relevant parameters (e.g., new Date(2024, 05, 05, 12, 00, 00, UTC)).
If my reply helped with your issue please mark it helpful and correct
if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having