How to get the current date-time till millisecond?

Mahesh Bachhav
Kilo Expert

I need to extract the current date-time in the below format - 

yyyy-mm-dd hh:mm:ss.ms

i.e I require milliseconds also to be displayed along with hours/minutes/seconds. 

e.g. Expected data-time = 2022-05-27 10:00:20.248

Please suggest the approach to get it.

Thanks in advance.

1 ACCEPTED SOLUTION

Mahesh Bachhav
Kilo Expert

Below code gives me the correct answer - 

var d = new GlideDateTime()
var ms = d.getNumericValue();
var dateTimeTillMs = new Date(ms).toISOString();
gs.info(dateTimeTillMs);

 

find_real_file.png

View solution in original post

3 REPLIES 3

JohnnySnow
Mega Sage

Hi Mahesh,

 

Can you try this

 

var gdt = new GlideDuration(urdatefield);
var value = gdt.getByFormat('HH:mm:ss ms');

This is not giving the correct answer. ms returns the minute and second in single digit.

Mahesh Bachhav
Kilo Expert

Below code gives me the correct answer - 

var d = new GlideDateTime()
var ms = d.getNumericValue();
var dateTimeTillMs = new Date(ms).toISOString();
gs.info(dateTimeTillMs);

 

find_real_file.png