Javascript Date Format Method

You are having trouble with this:

var now = new Date(); var timestamp = now.format("dd/mm/yyyy HH:MM:ss") + " (" + GetLoggedUserName() + ")"; 

I get: Object does not support the property or method 'format'

I was sure that this worked earlier than in other projects.

+5
source share
1 answer

The format() function is not standard for Date objects in javascript.

You most likely saw this in an application that uses a date formatting library such as moment.js.

http://momentjs.com/

 moment().format('MMMM Do YYYY, h:mm:ss a'); 

Your example can be rewritten in moment.js as follows:

 var timestamp = moment().format("DD/MM/YYYY HH:mm:ss") + " (" + GetLoggedUserName() + ")"; 
+6
source

All Articles