js 处理Json 时间带T 时间格式






<body>


<p id="demo">Click the button to display the date and time as a string, using the ISO standard.</p>


<button οnclick="myFunction()">Try it</button>


<script>
function myFunction()
{
var dateee = new Date("2017-07-09T09:46:49.667").toJSON();


var date = new Date(+new Date(dateee)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')  
   alert(date)	  


}
</script>

http://blog.csdn.net/hj7jay/article/details/51433745

点击打开链接

对于后台传过来的json数据是带T时间格式的坑处理的一些做法总结

new Date(data[j].addtime).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')

仅针对这个问题来说,不需要那么大量的代码即可完成

方案1(适用于中国标准时间):

[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. var date = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')  

方案2(只用于题目中所述的格式转换):

[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. var date = new Date().toLocaleString().replace(/[年月]/g,'-').replace(/[日上下午]/g,'');  

方案3(最准确但最麻烦,不推荐):

[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. var date = new Date();  
  2.   
  3. var result = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();  





















                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值