-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_date.txt
More file actions
34 lines (26 loc) · 939 Bytes
/
convert_date.txt
File metadata and controls
34 lines (26 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function convertDate(date)
{
var dateTimeParts = date.split(' ');
// # this assumes time format HAS SPACE between time and am/pm marks.
if(dateTimeParts[2] != undefined){
dateTimeParts[1]+=dateTimeParts[2];
}
var theTime = dateTimeParts[1];
var ampm = theTime.replace(/[0-9:]/g,'').trim();
var time = theTime.replace(/[[^a-zA-Z]/g,'').trim();
if(ampm == 'pm')
{
time_comp = time.split(':');
// # if time is 12:00, don't add 12
if(time[0] == 12) {
time = parseInt(time_comp[0]) + ':' + time_comp[1];
} else {
time = (parseInt(time_comp[0])+12) + ':' + time_comp[1];
}
}
time = time+':00';
var dt_comp = dateTimeParts[0].split("/").reverse();
var date = new Date(dt_comp.join('-')+'T'+time.trim()+'Z');
//console.log(dt_comp, time, ampm, date);
return date;
}//end func...