Time format is showing from 1970

Community Alums
Not applicable

Hi Team,

 

Below is the script I have written to do some time calculation

 var sla = new GlideRecord('task_sla');
        sla.addQuery('task', current.sys_id.toString());
        sla.addEncodedQuery('sla.target=resolution');
        sla.setLimit(1);
        sla.query();
        if (sla.next()) {

            pause = sla.pause_duration;
            rpch = sla.task.u_rpchs_duration;
            res = sla.task.u_mean_time_to_restore;
        }
 
I want to convert the above into minutes but if I do gs.info(pause) its giving time from 1970 . epoc time.
 
I did many things like , if I do
 
 var date = new GlideDateTime(pause);

        // Get the hour and minute components
        var time= date.getDisplayValue(); 
      
        gs.info('hours:' + time); // its printing hours:12/31/1969 16:14:55  
 
Can you tell how to convert in into minutes?
1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Community Alums,

 

You can leverage the .getDisplayValue() method.

Or if you need to convert the value try incorporating some of the below script in yours:

 

var epoch = new GlideDateTime().getNumericValue(); //This gives you the value in ms..

 

Now if you take that value and put it in

var gdt = new GlideDateTime();
gdt.setNumericValue(epoch);
gs.print(gdt);

It will return the current date/time in UTC time.

 

To get the Local time you can use gs.print(gdt.getDisplayValue());

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

View solution in original post

1 REPLY 1

Robbie
Kilo Patron
Kilo Patron

Hi @Community Alums,

 

You can leverage the .getDisplayValue() method.

Or if you need to convert the value try incorporating some of the below script in yours:

 

var epoch = new GlideDateTime().getNumericValue(); //This gives you the value in ms..

 

Now if you take that value and put it in

var gdt = new GlideDateTime();
gdt.setNumericValue(epoch);
gs.print(gdt);

It will return the current date/time in UTC time.

 

To get the Local time you can use gs.print(gdt.getDisplayValue());

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie