Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Issue with timezone

Sathwik1
Tera Guru

My instance is in Australia/West Timezone, and I use below code...  after record creation... frond end time and backend XML timings are different,, I want both frontend and backend start time should be 6:00:00 and 10:00:01

var daysToCreate = 60;
var gdt = new GlideDateTime();

for (var i = 1; i <= daysToCreate; i++) {

    gdt.addDaysLocalTime(1);

    var day = gdt.getDayOfWeekLocalTime();

    if (day < 2 || day > 5) {
        continue;
    }

    var dateStr = gdt.getLocalDate().toString();

    createSlot(dateStr, "06:00:00", "10:00:00");
    createSlot(dateStr, "10:00:01", "14:00:00");
}

function createSlot(date, startTime, endTime) {

    var start = new GlideDateTime();
    start.setDisplayValue(date + " " + startTime);

    var end = new GlideDateTime();
    end.setDisplayValue(date + " " + endTime);

    var check = new GlideRecord('u_deploy');
    check.addQuery('u_start_time', start);
    check.setLimit(1);
    check.query();

    if (check.next()) {
        return;
    }

    var slot = new GlideRecord('u_deploy');
    slot.initialize();
    slot.u_start_time = start;
    slot.u_end_time = end;
    slot.insert();
}

 

@Tanushree Maiti @Ankur Bawiskar 

1 ACCEPTED SOLUTION

Tanushree Maiti
Kilo Patron

Hi @Sathwik1 

 

As per following article:

Best Practices

  • Always verify the time zone abbreviation you are using (e.g., some time zones may require full names like "America/New_York").

  • Consider user preferences and system settings when converting times dynamically.

  • Store and process all timestamps in UTC to ensure consistency across global applications.

 

Refer this article - Converting Date/Time into Any Time Zone in ServiceNow

with sample code 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

4 REPLIES 4

An Le
Giga Sage

Hi @Sathwik1 ,

The record is behaving as expected. In ServiceNow, Date/Time fields are stored in the database in UTC, while the form displays them in the user’s local time zone.

the values look different, they represent the same timestamp.

It may also help to look at functions such as setDisplayValueInternal() and getDisplayValueInternal().

Kind regards,

Ankur Bawiskar
Tera Patron

@Sathwik1 

in backend means in XML it always stored in UTC

But in UI it shows as per user's timezone

Please discuss with your customer what value they wish to set i.e. UTC or user's local timezone and accordingly update the code

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@Sathwik1 
I could see you closed the thread by marking response as correct.

So what was the issue and what worked for you?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Tanushree Maiti
Kilo Patron

Hi @Sathwik1 

 

As per following article:

Best Practices

  • Always verify the time zone abbreviation you are using (e.g., some time zones may require full names like "America/New_York").

  • Consider user preferences and system settings when converting times dynamically.

  • Store and process all timestamps in UTC to ensure consistency across global applications.

 

Refer this article - Converting Date/Time into Any Time Zone in ServiceNow

with sample code 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: