简体   繁体   English

如何基于从php返回的日期对象在jquery中创建新的日期对象?

[英]how can I create a new Date object in jquery based on the date object returned from php?

I have a php script that returns date in tokyo in a following format: 我有一个php脚本,它以以下格式返回东京的日期:

Thu, 01 Oct 2015 06:10:09 +0900

I already passed it to my jquery script with ajax and now store it in local variable 我已经使用ajax将其传递给我的jquery脚本,现在将其存储在本地变量中

var myTime = 'Thu, 01 Oct 2015 06:10:09 +0900

Now I want to create a new Date() object with that data, so then I can have an actual date from tokyo on my webpage without using local client's timezone. 现在,我想使用该数据创建一个新的Date()对象,这样就可以在不使用本地客户端时区的情况下,在网页上获得东京的实际日期。 How can I do that? 我怎样才能做到这一点?

If your PHP code returns just that string: 如果您的PHP代码仅返回该字符串:

<?PHP echo "Thu, 01 Oct 2015 06:10:09 +0900"; ?>

Then in your jQuery ajax return: 然后在您的jQuery ajax中返回:

function(data) 
{
    var myDate = new Date(data.trim());
    //...
}//..

Example: of the raw string in jsfiddle JsFiddle 示例:jsfiddle中的原始字符串JsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM