time conversions
inを使用してdatetimepicker
injs
を変換しdate
ているときに違いが生じますphp
私のPHPコードは次のとおりです。
<?php
date_default_timezone_set('Asia/Calcutta');
echo date('Y-m-d H:i:s A',strtotime('5/29/2013 00:00PM'));
//outputs 1970-01-01 05:30:00 AM
//echo date('Y-m-d H:i:s A',strtotime('5/29/2013 0:00AM'));//same result
//tested on http://writecodeonline.com/php/
?>
そしてjs
<script>
var s='5/29/2013 0:00PM';
parseDate= function(s) {
var currentYear, currentMonth, currentDay, currentHour, currentMinute;
arr=s.split(' ');
dateArr=arr[0].split('/');
currentYear=dateArr[2];
currentMonth=parseInt(dateArr[0])-1;
currentDay=dateArr[1];
timeArr=arr[1].split(':');
currentHour=timeArr[0];
if(s.contains('AM')===false)
{
currentHour=parseInt(timeArr[0])+12;
currentMinute=parseInt(timeArr[1].replace('PM'));
}
else
{
currentMinute=parseInt(timeArr[1].replace('AM'));
}
console.log(currentYear,currentMonth,currentDay,currentHour,currentMinute,0,s.contains('AM'));
return new Date(currentYear,currentMonth,currentDay,currentHour,currentMinute,0);
}
console.log(new Date());
alert(parseDate(s));
//outputs Wed May 29 2013 12:00:00 GMT+0530 (India Standard Time)
</script>