Reputation: 23379
I am currently using ajax to execute the following php code which deconstructs a date/time string.
//date string
$date = "20 November, 2013";
//time string
$time = "9:30 AM";
// get timestamp for date
$dtime = strtotime($date);
//get day of month - 20
$DAY = date("d",$dtime);
//get month - 11
$MONTH = date("m",$dtime);
//get timestamp for time
$ttime = strtotime($time);
//get hour - 09
$HOUR = date("h",$ttime);
//get min - 30
$MIN = date("i",$ttime);
//get meranda - AM
$MER = date("A", $ttime);
How can I get these same values using the JS Moment library from any string in the above format?
Upvotes: 0
Views: 1338
Reputation: 214979
You question is not very clear, but consider:
moment("20 November, 2013, 9:30 AM UTC").format()
returns (in my TZ):
"2013-11-20T10:30:00+01:00"
or, you can obtain date parts from the moment
object like this:
date = moment("20 November, 2013, 9:30 AM");
hour = date.hour()
etc, see the docs.
Upvotes: 1