包含“Z”的日期格式 [英] Date format containing "Z"

查看:143
本文介绍了包含“Z”的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我处于日期导致问题的情况。当选择的日期格式为dd.mm.yyyy(德语)时,我有一个日期选择器。然后我需要传递给REST API(Sharepoint),它允许时间包含Z(zulu => UTC)。所以我把这个日期改成了这个



Hi,

I am in a scenario where date is causing problem. I have a date picker when selected date is of format dd.mm.yyyy (German). I need to then pass to REST API(Sharepoint) where it allows time containing Z (zulu=>UTC). So i converted the date like this

var tmpAuditDate = $(this).parent().find('[id*=Date]').val(); //value from date picker
      var auditDate = "";
      if (tmpAuditDate) {
          var dString = tmpAuditDate.split(dateSeparator);
          if (dateSeparator == ".") {
              auditDate = new Date(dString[2], dString[1] - 1, dString[0]);
          }
          else {
              auditDate = new Date(dString[2], dString[0] - 1, dString[1]);
          }
          auditDate.setDate(auditDate.getDate());
      }





我的审核日期为Tue Feb 3 00:00:00 UTC + 0530 2015但是当我将它传递给REST时它会抛出错误,不允许原始类型,当我检查其余的api结果时,它是以Edm.DateTime格式。所以我用这个转换了日期





I got the audit date as this "Tue Feb 3 00:00:00 UTC+0530 2015" but when i pass it to REST it throws an error, primitive types are not allowed and when i checked the rest api result its in Edm.DateTime format. So i converted the date using this

auditDate.toISOString()



虽然它已成功保存,但我得到的结果是2015-02-02T18:30:00.000Z,这是一天的回归。



所以我怎样才能实现这个目标。



如果浏览器不支持此处指定的函数,我也看到了ISOString转换的实现 ISO



但我应该把它放在哪里???



提前谢谢

Arjun Menon


Although it was saved successfully the date i got the result like this "2015-02-02T18:30:00.000Z", which is a day back.

So how can i achieve this.

Also i saw an implementation of ISOString convertion if browser doesnot support the function as specified here ISO

But where shall i put this???

Thanks in advance
Arjun Menon

推荐答案

this )。parent()。find(' < span class =code-string> [id * = Date]')。val(); // 日期选择器的值
var auditDate = ;
if (tmpAuditDate){
var dString = tmpAuditDate.split(dateSeparator) ;
if (dateSeparator == ){
auditDate = new 日期(dString [ 2 ],dString [ 1 ] - 1 ,dString [< span class =code-digit> 0 ]);
}
else {
auditDate = new 日期(dString [ 2 ],dString [ 0 ] - 1 ,dString [ 1 ]);
}
auditDate.setDate(auditDate.getDate());
}
(this).parent().find('[id*=Date]').val(); //value from date picker var auditDate = ""; if (tmpAuditDate) { var dString = tmpAuditDate.split(dateSeparator); if (dateSeparator == ".") { auditDate = new Date(dString[2], dString[1] - 1, dString[0]); } else { auditDate = new Date(dString[2], dString[0] - 1, dString[1]); } auditDate.setDate(auditDate.getDate()); }





我的审核日期为Tue Feb 3 00:00:00 UTC + 0530 2015但是当我将它传递给REST时它会抛出错误,不允许原始类型,当我检查其余的api结果时,它是以Edm.DateTime格式。所以我用这个转换了日期





I got the audit date as this "Tue Feb 3 00:00:00 UTC+0530 2015" but when i pass it to REST it throws an error, primitive types are not allowed and when i checked the rest api result its in Edm.DateTime format. So i converted the date using this

auditDate.toISOString()



虽然它已成功保存,但我得到的结果是2015-02-02T18:30:00.000Z,这是一天的回归。



所以我怎样才能实现这个目标。



如果浏览器不支持此处指定的函数,我也看到了ISOString转换的实现 ISO



但是我应该把它放在哪里???



提前谢谢

Arjun Menon


Although it was saved successfully the date i got the result like this "2015-02-02T18:30:00.000Z", which is a day back.

So how can i achieve this.

Also i saw an implementation of ISOString convertion if browser doesnot support the function as specified here ISO

But where shall i put this???

Thanks in advance
Arjun Menon

有趣的问题..感谢询问......请在此处找到解决方案:

http://stackoverflow.com/questions/2587345/javascript-date-parse?lq=1 [ ^ ]



http://stackoverflow.com/questions/7556591/javascript-date-object-always-one-day-关闭 [ ^ ]



http://stackoverflow.com/questions/14976457/initializing-javascript-date-with-iso-8601-date-string-produces- date-value-1-da?lq = 1 [ ^ ]



谢谢。
Interesting question..Thanks for asking...Please find resolution here:
http://stackoverflow.com/questions/2587345/javascript-date-parse?lq=1[^]

http://stackoverflow.com/questions/7556591/javascript-date-object-always-one-day-off[^]
and
http://stackoverflow.com/questions/14976457/initializing-javascript-date-with-iso-8601-date-string-produces-date-value-1-da?lq=1[^]

Thanks.


我想我找到了解决方案。

var tmpA uditDate =
I think i found the solution.
var tmpAuditDate =


这篇关于包含“Z”的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆