datetime jquery asp.net mvc的问题 [英] issue with datetime jquery asp.net mvc

查看:63
本文介绍了datetime jquery asp.net mvc的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对日期有疑问.在我的Model类中,我使用了DateTime属性(我使用了Code First),用于将json数据从一个动作传输到另一个动作,我使用了Jquery($ .ajax),我的日期以这种格式转换,我认为是毫秒:

I have an issue with date.In my Model class I have used DateTime property(I used Code First), for transferring json data from action to another action I use Jquery ($.ajax), my date convert in this format, I think it milliseconds:

/Date(1188594000000)/

我尝试使用js对其进行转换,但无法正常工作: var date = new Date(mydate);

I tryed to convert it using js, not working: var date = new Date(mydate);

推荐答案

/Date(1188594000000)/是一个字符串,括号内的长数字是自unix纪元时间开始以来的毫秒数.您不能将其(字符串原样)传递给Date构造函数.如果要从该值生成日期时间对象,则应删除前6个字符(/Date()并仅传递毫秒

/Date(1188594000000)/ is a string and the long numbers inside the brackets are the milliseconds since the beginning of the unix epoch time. You cannot pass that(the string as it is) to Date constructor. If you want to generate a datetime object from that value, you should remove the first 6 characters (/Date() and pass the milliseconds only

var mydate='/Date(1188594000000)/';
var dateVal= parseInt(mydate.substr(6));
var dateObj= new Date(dateVal);
console.log(dateObj);

语句mydate.substr(6)将返回类似于"1188594000000)/"的字符串值,并将其传递给parseInt方法将返回数字1188594000000,该数字可以安全地传递给Date构造函数.

The statement mydate.substr(6) will return a string value like "1188594000000)/" and passing this to parseInt method returns the number 1188594000000 which can be safely passed to the Date constructor.

这篇关于datetime jquery asp.net mvc的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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