I have this Date Format var 开发者_JS百科date = 'Jun 2, 2011 3:05:14 PM';
I want to split it in such a way that i should get only Hours from this
Could anybody please help me .
Thank you .
Create a Date first, then get the hours:
var date = new Date('Jun 2, 2011 3:05:14 PM');
var hours = date.getHours();
If you want 3 instead of 15, add this:
if (hours > 12) hours -= 12;
Midnight will return 0. To get 12 instead, add this:
if (hours == 0) hours = 12;
Use the string to create a date object which grants you methods to traverse it:
new Date('Jun 2, 2011 3:05:14 PM').getHours();
Try this:
var date = 'Jun 2, 2011 3:05:14 PM';
var hours = new Date(date).getHours();
var date = 'Jun 2, 2011 3:05:14 PM',
hours=date.split(/\W+/)[3];
Without a time zone, dates are not portable.
加载中,请稍侯......
精彩评论