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
chikkuchikku 

How can I format a date object to print as today instead of showing a numeric date in a javascript?

I'd like to display it like this: today At 5:00 PM.
User-added image
This my code 

var today = new Date();
        var date = new Date(today)
        date.setDate(date.getDate()-1)
        today.toDateString()
        date.toDateString()
        var time = today.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
        var dateTime = date+' '+time;
        this.dateTimeValue=dateTime;

 
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

Please find the sample javascript to get the current date:
 
var currentdate = new Date(); 
var datetime = "Last Sync: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();
Reference:https://stackoverflow.com/questions/10211145/getting-current-date-and-time-in-javascript

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri