[英]php and ajax pass date strtotime converstion is different
My code for gettin date in jquery is given below : 我在jQuery中获取日期的代码如下:
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
var splits =url.split('?');
if(splits[1])
{
var splits2 = splits[1].split('=');
var newDate = splits2[1];
}
else
{
var date = new Date(),
yr = date.getFullYear(),
month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(),
day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
newDate = yr + '-' + month + '-' + day;
}
After this i am sending this to php code : 在此之后,我将其发送到php代码:
$.ajax({
type:'post',
url:'<?php echo BASE_URL; ?>dashboard/get_weedays',
async:false,
data:{date : newDate},
success:function(response)
{
var obj = JSON.parse(response);
design_for_week(obj);
}
})
In php i am getting this date and converting it into strtotime
but its returning me the different values .In php i am doing this
但它返回我不同的价值。在PHP中,我正在这样做
$date = $this->input->post("date");
$dt = strtotime($date);
echo $dt;exit;
for date 2018-11-06 timestamp in php is : 1541442600
but when i pass the date from the ajax and after getting it on php it return me timestam like : 1541442600 但是,当我通过ajax传递日期并在php上获取日期后,它会返回我timestam,例如:1541442600
both are different can anyone please suggest me fo this ? 两者都不同,有人可以为此建议我吗? how can i solve this 1541615400
我该如何解决这1541615400
Transfer UTC timestamp from client, to avoid timezone difference between client and server. 从客户端传输UTC时间戳,以避免客户端和服务器之间的时区差异。
In javascript get UTC timestamp: 在javascript中获取UTC时间戳:
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
var splits =url.split('?');
if(splits[1])
{
var splits2 = splits[1].split('=');
var getDate = splits2[1];
var datum = Date.parse(getDate); // gets date//
var newDate = Math.floor(datum/1000);
//console.log(newDate);
}
else
{
var date = new Date(new Date().toUTCString());
var jsmonth = date.getMonth()+1;
var yr = date.getFullYear(),
var month = jsmonth < 10 ? '0' + jsmonth : jsmonth, //january is 0
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
var getDate = yr + '-' + month + '-' + day;
var datum = Date.parse(getDate);
var newDate = Math.floor(datum/1000);
//console.log(newDate);
}
read more: How do I get a UTC Timestamp in JavaScript? 阅读更多: 如何获取JavaScript中的UTC时间戳?
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
var splits =url.split('?');
if(splits[1])
{
var splits2 = splits[1].split('=');
var newDate = (new Date(splits2[1])).toUTCString();
date = new Date(newDate).getTime()/1000;
}
else
{
var dates = (new Date()).toUTCString();
date = new Date(dates).getTime()/1000;
}
For this we need to do like this because u need to covert tiem inti utc then divided this from 1000 because its a client time 为此,我们需要这样做,因为您需要隐秘tiem inti utc,然后将其除以1000,因为这是客户时间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.