5

Having trouble with this:

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

I get: Object doesn't support property or method 'format'

I was sure this worked before though on other projects..

2
  • 2
    other projects may have had js library for date (datejs, momentjs, etc) Commented Jul 29, 2015 at 12:27
  • 1
    You can always check the documentation on MDN to see all available properties for the Date constructor. Commented Jul 29, 2015 at 12:35

1 Answer 1

6

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

You have most likely seen this in an application running a date formatting library such as moment.js.

http://momentjs.com/

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

Your example could be rewrote in moment.js like this:

var timestamp = moment().format("DD/MM/YYYY HH:mm:ss") + " (" + GetLoggedUserName() + ")";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.