Reputation: 353
How to do the following in JavaScript?:
$curr_time_start = new DateTime();
$timeStart = date_format($curr_time_start, 'Y-m-d H:i');
Upvotes: 0
Views: 128
Reputation: 9758
Natively it's not possible to do such a thing with Javascript.
There are many ways to accomplish that using frameworks or specific libraries.
For example, with MooTools you can do this:
var timeStart = new Date().format('%Y-%m-%d %H:%M');
You can test this with this JsFiddle.
The syntax for the format is almost the same, but for the %M
instead of i
for the minutes, and because all the placeholders are prefixed by %
.
Upvotes: 1
Reputation: 6749
Probably something like
var d = new Date();
alert(
d.getYear() + '-' + d.getMonth() + '-' + d.getDay() + ' ' +
d.getHours() + ':' + d.getMinutes());
Upvotes: 1
Reputation: 29025
Try date.js
Datejs is an open-source JavaScript Date Library.
Comprehensive, yet simple, stealthy and fast. Datejs has passed all trials and is ready to strike. Datejs doesn’t just parse strings, it slices them cleanly in two.
Upvotes: 0
Reputation: 7991
I normally use the plugin from Matt Kruse -
http://javascripttoolbox.com/lib/date/
Upvotes: 1