Michael
Michael

Reputation: 10303

JavaScript utility for date formatting

I would like to use a utility function, which I can use as follows:

var d = new Date();
formatDate(d, "YYYY-mm-dd HH:MM:ss");

I know I can implement this function by myself but I would like to use something "standard". Besides I would like this function to run in both client side and server side (i.e. in browser and node.js) and not to bring unnecessary dependencies. (for example, I would not like to use a jQuery function)

There are a lot of Q&A about date formatting but I am still not sure if there is a utility

Upvotes: 1

Views: 7330

Answers (3)

Simeon
Simeon

Reputation: 5579

This lightweight library is what you need. Just remove unwanted parts of it.

http://momentjs.com/

Upvotes: 3

Digbyswift
Digbyswift

Reputation: 10400

Use date.js with the folowing code:

var d = Date.today().set({ day: 15, hour: 8, minute: 30 });
d.toString("YYYY-mm-dd HH:MM:ss");

Upvotes: 1

qwertymk
qwertymk

Reputation: 35256

Check out

Date.js

It should do what you're looking for

Upvotes: 1

Related Questions