Reputation: 10303
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
Reputation: 5579
This lightweight library is what you need. Just remove unwanted parts of it.
Upvotes: 3
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