168
rated 0 times
[
173]
[
5]
/ answers: 1 / hits: 28540
/ 14 Years ago, thu, january 13, 2011, 12:00:00
The format is:
MMDDHHMM
I want to take month, day, hour, minute individually, how to do that?
More From » jquery
The format is:
MMDDHHMM
I want to take month, day, hour, minute individually, how to do that?
var dateString = '13011948';
The length of the text is fixed and always at the same position. Then you can just use substr
to cut them into parts and use parseInt
to convert them to number.
var month = parseInt(dateString.substr(0, 2), 10),
day = parseInt(dateString.substr(2, 2), 10),
hour = parseInt(dateString.substr(4, 2), 10),
minute = parseInt(dateString.substr(6, 2), 10);
Or instead, put it in a single date object.
var date = new Date();
date.setMonth (parseInt(dateString.substr(0, 2), 10) - 1);
date.setDate (parseInt(dateString.substr(2, 2), 10));
date.setHours (parseInt(dateString.substr(4, 2), 10));
date.setMinutes (parseInt(dateString.substr(6, 2), 10));