如何将此JSON数据格式化为日期(mm / dd / yyyy) [英] How to format this JSON data to date(mm/dd/yyyy)

查看:286
本文介绍了如何将此JSON数据格式化为日期(mm / dd / yyyy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例JSON:

[{"DispatchDt":"2014-05-28T01:34:00","RcvdDt":"1988-12-26T00:00:00"}]

我有这套日期我想将其转换为日期格式(mm / dd / yyyy)。你如何做这个JavaScript?

I have this set of dates and I want to convert it to the date format (mm/dd/yyyy). How do you do this is JavaScript?

推荐答案

你可以将json字符串格式化为 new Date() 然后使用js方法来获取月,日,年或你所需要的。

You may format the json string into new Date() then use js methods to get month,day,year or what exactly you need.

   //format string to datetime
   var DispatchDt = new Date(this.DispatchDt);


   // then use this methods to fetch date,month, year needed
   //getDate() // Returns the date
   //getMonth() // Returns the month
   //getFullYear() // Returns the year
    var DispatchDt_date = DispatchDt.getDate();
    var DispatchDt_month = DispatchDt.getMonth() + 1; //Months are zero based
    var DispatchDt_year = DispatchDt.getFullYear();

jsFiddle上的示例

这篇关于如何将此JSON数据格式化为日期(mm / dd / yyyy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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