function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ruturaj R DRuturaj R D 

How to extract time from createdDate field of custom object in javascript?

Best Answer chosen by Ruturaj R D
Niraj Kr SinghNiraj Kr Singh
Hi Ruturaj,

I am assuming your are getting your createdDate in javascript code. After that you can try this:

var date = new Date();
date = your createdDate here;
var UTC = date.toUTCString();
var time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
console.log(time);
console.log(UTC);
console.log(date);

If it helps you, mark this your ans.

Thanks
Niraj

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

You may try something like below.
 
var ts = new Date();
console.log(ts.toTimeString());

Refer below link.
https://timestamp.online/article/how-to-convert-timestamp-to-datetime-in-javascript
 
Best Regards,
Sandhya
Niraj Kr SinghNiraj Kr Singh
Hi Ruturaj,

I am assuming your are getting your createdDate in javascript code. After that you can try this:

var date = new Date();
date = your createdDate here;
var UTC = date.toUTCString();
var time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
console.log(time);
console.log(UTC);
console.log(date);

If it helps you, mark this your ans.

Thanks
Niraj
This was selected as the best answer
Ruturaj R DRuturaj R D
Thanks Niraj,That worked for me..