将.NET DateTime对象转换为Javascript Date对象 [英] converting .NET DateTime object to Javascript Date object

查看:59
本文介绍了将.NET DateTime对象转换为Javascript Date对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下问题:

我从SQL Server中检索DateTime对象,并将其通过JSON(使用$ .ajax)传递给Javascript.我在尝试将检索到的对象转换为javascript中的Date对象时遇到了困难. 检索到的对象是值"/Date(615592800000)/"的字符串.我认为这是一个时代.

I retrieve a DateTime object from SQL Server and pass it via JSON (using $.ajax) to Javascript. I have experienced difficulty trying to convert the retrieved object to a Date object in javascript. The retrieved object is a string of value "/Date(615592800000)/". I think the value is an epoch time.

我的问题是,除了使用正则表达式选择时期值然后创建一个新的Date对象,还有别的检索日期对象的方法吗?

My question is, is there another way of retrieving the date object than to use regex to select the epoch value and then create a new Date object?

我是JS的新手,所以我们将不胜感激.

I'm fairly new to JS, so any help would be appreciated.

推荐答案

我不知道...这是我正在使用的功能,以防万一...

not that I know... this is the function i'm using, just in case ...

function toDateFromJson(src) {
    return new Date(parseInt(src.substr(6)));
}

这篇关于将.NET DateTime对象转换为Javascript Date对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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