时间格式转换 json 转 datetime js c#
情景描述:使用C#在后台中传递时间到ajax中,因为是一个list<model>就直接用了Json 作为载体,但是在js中获得到的时间是var time='/Date(***************)/';
初次判断为时间戳,直接转换 new Date(time); 失败,仔细看才发现是因为json时间转化的问题
一:底层方法
[HttpPost]
public JsonResult AjaxReviewForBranchDetail(int PageIndex, int BranchID)
{
PageIndex++;
var reviewlist = this.WebSiteService.GetReviewList(new ReviewRequest() { BranchID = BranchID, PageIndex = PageIndex }, true);
return Json(new { reviews = reviewlist.Select(r => new { r.Content, r.CreateDate, r.CompositeScore, r.UserName }) }); }
二:js 接收
//点评数据
function getmorereview() {
$.ajax({
url: "AjaxReviewForBranchDetail",
type: "post",
data: { PageIndex: $("#reviewpageindex").val(), BranchID: $("#HidBranchID").val() },
success: function (date) {
var html = "";
if (date != null) {
if (date.reviews.length > ) { for (var i = ; i < date.reviews.length; i++) { html += "<dl class=\"commentdetails\">";
html += "<div class=\"left imgb\">";
html += "<i class=\"icon cusimg\"></i>";
html += "</div>";
html + "<div class=\"left commentcontent\">";
html += "<div>";
html += "<span class=\"username\">" + date.reviews[i].UserName + "</span>";
html += "<div class=\"icon star\" style=\"display: inline-block;\">";
html += "<i class=\"icon progress5\"></i>";
html += "</div>";
html += "<span class=\"scores\">" + date.reviews[i].CompositeScore + "分</span> <span class=\"time\">" + getLocalTime(date.reviews[i].CreateDate) + "</span>";
html += "</div>";
html += "<p class=\"cont\">";
html += date.reviews[i].Content;
html += "</p>";
html += "</div>";
html += "</dl>";
}
$("#reviewpageindex").val(parseInt($("#reviewpageindex").val()) + );
} } else {
html += "<span>亲,这回真没了!</span>";
}
$("#reviewdiv").append(html);
}
})
}
三:json转datetime
//时间json转datetime
function getLocalTime(dateText) {
dateText = dateText.replace("/Date(", "").replace(")/", "").substring(, );
/*
需要注意的是:
不要把字符串中的Date(这样的字符也传进去,要先处理一下,这样很方便就能处理的
可以使用replace方法
如:replace("/Date(","").replace(")/","");
*/
//返回 2014年5月26日 下午12:00
//return new Date(parseInt(dateText) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
//返回 2014年5月26日 下午12:0
//return new Date(parseInt(dateText) * 1000).toLocaleString().substr(0, 17);
//返回 2014-5-26 12:00:29
return new Date(parseInt(dateText) * ).toLocaleString().substr(, ).replace(/年|月/g, "-").replace(/日/g, " ").replace(/上|午/g, " ").replace(/下|午/g, " ");
}
ps:我要的是年-月-日所以就substr(0,12),这个根据个人需求判定
时间格式转换 json 转 datetime js c#的更多相关文章
- js 时间格式转换
js时间格式转换 格式化时间转成时间戳 //格式化转时间戳(单位秒) function strtotime(strtime) { strtime = strtime.substring(0, 19); ...
- moment.js 时间格式转换
moment.js 时间格式转换 moment.js 时间转化 bug 格式错误 bug 02:00 => 14:00 format HH 与 hh HH === 24 小时制 hh === 1 ...
- SQL Server日期时间格式转换字符串详解 (详询请加qq:2085920154)
在SQL Server数据库中,SQL Server日期时间格式转换字符串可以改变SQL Server日期和时间的格式,是每个SQL数据库用户都应该掌握的.本文我们主要就介绍一下SQL Server日 ...
- SQL Server日期时间格式转换字符串
在SQL Server数据库中,SQL Server日期时间格式转换字符串可以改变SQL Server日期和时间的格式,是每个SQL数据库用户都应该掌握的.本文我们主要就介绍一下SQL Server日 ...
- Sql日期时间格式转换;取年 月 日,函数:DateName()、DATEPART()
一.sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007 ...
- SQL Server日期时间格式转换字符串详解
本文我们主要介绍了SQL Server日期时间格式转换字符串的相关知识,并给出了大量实例对其各个参数进行对比说明,希望能够对您有所帮助. 在SQL Server数据库中,SQL Server日期时间格 ...
- sql 日期时间格式转换
Sql日期时间格式转换 sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, ...
- Java json设置时间格式,Jackson设置时间格式,json设置单引号
Java json设置时间格式,Jackson设置时间格式,json设置单引号 >>>>>>>>>>>>>>> ...
- 时间格式的转化 vue与js 年月日 时分秒
首先使用原生转化的方法 第一种 //时间转换 dateStr(d, sign) { //如果没有传递符号,给一个默认的符号 if (!sign) { sign = '-' } //获取d里面年月日时分 ...
随机推荐
- 使用IntelliJ IDEA创建Maven多模块项目
转载:http://blog.csdn.net/xyw591238/article/details/52794788 使用Maven管理项目时,往往需要创建多个模块,模块之间存在相互引用的关系.对于M ...
- Oracle安装过程中的几点注意
为追求统一,安装了oracle 11g step 4时需要改一下名称,利于记忆 数据库安装完之后需要取消SCOTT账户的锁定 完成后点击SQL Developer会出现——"应用程序开发&q ...
- VB的第一个项目
前言-----本人也是刚刚接触VB,企业的VB代码基本能看的懂,但是自己开发,只能呵呵.一般在刚学习一门新的语言时,很容易发生一些自己相当然的认识错误,so,记下并分享开发学习的过程,望指正.--- ...
- android中几个很有用的的api
0x0001 public PackageInfo getPackageArchiveInfo (String archiveFilePath, int flags) Since: API Level ...
- MVC | 微软自带的Ajax请求
@Ajax.BegForm( ) 用来生成异步表单 Home控制器 using System; using System.Collections.Generic; using System.Linq ...
- PHP获取QQ群成员QQ号码
.加入某个群 .进入群空间http://qun.qzone.qq.com/group#!/25998059/member 备注:25998059为群号码 .进入群成员列表 .使用浏览,在某个群成员头像 ...
- 外部jar包 @Service 无法注解无法扫描问题
在确保spring 配置 无误的情况下,如: <context:component-scan base-package="your.can.pakeage"></ ...
- csla 与高cpu
在项目中一直使用csla 4.13. 项目一直正常,但是偶尔会出现iis占用的cpu 突然100%, 后面客户量大的情况,加入了缓存的机制.100%的情况出现的更多了. 当时有数据库死锁的原因.cpu ...
- Linux Linux程序练习三
/* index1 = 45 index2 = 36 index3 = 231 index4 = 43 index5 = 100 index6 = 123 index7 = 51 * * 通过读取读取 ...
- Oracle常见死锁发生的原因以及解决方法
Oracle常见死锁发生的原因以及解决办法 一,删除和更新之间引起的死锁 造成死锁的原因就是多个线程或进程对同一个资源的争抢或相互依赖.这里列举一个对同一个资源的争抢造成死锁的实例. Oracle 1 ...