日期格式如何转换为 JSON [英] How Date format is converted to JSON
本文介绍了日期格式如何转换为 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能解释一下这种日期格式吗?这是我的表 id=8
数据(我不理解这种格式):
id=8|startTime=1900-02-20 00:00:00|endTime=1900-02-20 00:00:00|AverageMeetTime=60|idDoctor=3|cancelled=0|permanentlyCancelled=0
JSON 格式显示:
<代码> {平均会议时间":60,取消":假,结束时间":{日期":20,天":5,小时":0,分钟":0,月":1,秒":0,时间":1424370600000,时区偏移":-330,年份":115},id":8,idDoctor":3,永久取消":假,开始时间":{日期":20,天":5,小时":0,分钟":0,月":1,秒":0,时间":1424370600000,时区偏移":-330,年份":115}}
你能解释一下这个日期格式吗:
+------------+------------+---------------------+-----------------+------------------+------------------------+-------------+|idTimeSlot |开始时间 |结束时间 |平均会议时间 |Doctor_idDoctor |isPermanentlyCancelled |已取消 |+------------+-------------+---------------------+-----------------+------------------+------------------------+--------------+|1 |2016-02-20 01:00:00 |2016-02-20 02:00:00 |20 |3 |0 |0 ||2 |2016-02-21 01:00:00 |2016-02-21 02:00:00 |60 |3 |0 |0 ||3 |2016-02-22 01:00:00 |2016-02-22 02:00:00 |60 |3 |0 |0 ||4 |2016-02-23 01:00:00 |2016-02-23 02:00:00 |60 |3 |0 |0 ||5 |2016-02-24 01:00:00 |2016-02-24 02:00:00 |60 |3 |0 |0 ||6 |2016-02-25 01:00:00 |2016-02-25 02:00:00 |60 |3 |0 |0 ||7 |2016-02-26 01:00:00 |2016-02-26 02:00:00 |60 |3 |0 |0 ||8 |1900-02-20 00:00:00 |1900-02-20 00:00:00 |60 |3 |0 |0 |+------------+-------------+---------------------+-----------------+------------------+------------------------+--------------+
解决方案
你需要将 JSON 对象存储到一个变量中才能使用它的属性来创建 Date
对象,因为这个 JSON 对象不是 Date
对象代码>日期代码>类型.您可以使用 JavaScript Dates
中的任何构造函数.><块引用>
而且我只想要这种格式.....(yyyy-MM-dd)
您可以使用 time
属性.
var json = {"endTime": {日期":20,天":5,小时":0,分钟":0,月":1,秒":0,时间":1424370600000,时区偏移":-330,年":115}};document.getElementById("demo").innerHTML = new Date(json.endTime.time).toLocaleFormat("%Y-%m-%d");
Can you any one explain this date format . This is my table id=8
data (I am not understanding this format):
id=8|startTime=1900-02-20 00:00:00|endTime=1900-02-20 00:00:00
|AverageMeetTime=60|idDoctor=3|cancelled=0|permanentlyCancelled=0
JSON format shows this:
{
"averageMeetTime": 60,
"cancelled": false,
"endTime":
{
"date": 20,
"day": 5,
"hours": 0,
"minutes": 0,
"month": 1,
"seconds": 0,
"time": 1424370600000,
"timezoneOffset": -330,
"year": 115
},
"id": 8,
"idDoctor": 3,
"permanentlyCancelled": false,
"startTime":
{
"date": 20,
"day": 5,
"hours": 0,
"minutes": 0,
"month": 1,
"seconds": 0,
"time": 1424370600000,
"timezoneOffset": -330,
"year": 115
}
}
Can you explain this date format:
+------------+---------------------+---------------------+-----------------+-----------------+------------------------+-------------+
| idTimeSlot | startTime | endTime | averageMeetTime | Doctor_idDoctor | isPermanentlyCancelled | isCancelled |
+------------+---------------------+---------------------+-----------------+-----------------+------------------------+-------------+
| 1 | 2016-02-20 01:00:00 | 2016-02-20 02:00:00 | 20 | 3 | 0 | 0 |
| 2 | 2016-02-21 01:00:00 | 2016-02-21 02:00:00 | 60 | 3 | 0 | 0 |
| 3 | 2016-02-22 01:00:00 | 2016-02-22 02:00:00 | 60 | 3 | 0 | 0 |
| 4 | 2016-02-23 01:00:00 | 2016-02-23 02:00:00 | 60 | 3 | 0 | 0 |
| 5 | 2016-02-24 01:00:00 | 2016-02-24 02:00:00 | 60 | 3 | 0 | 0 |
| 6 | 2016-02-25 01:00:00 | 2016-02-25 02:00:00 | 60 | 3 | 0 | 0 |
| 7 | 2016-02-26 01:00:00 | 2016-02-26 02:00:00 | 60 | 3 | 0 | 0 |
| 8 | 1900-02-20 00:00:00 | 1900-02-20 00:00:00 | 60 | 3 | 0 | 0 |
+------------+---------------------+---------------------+-----------------+-----------------+------------------------+-------------+
解决方案
You need to store JSON object to a variable to use its properties to create Date
object, because this JSON object is not of Date
type. You can use any constructor from the JavaScript Dates
.
And I want this format only .....(yyyy-MM-dd)
You can use time
property.
var json = {"endTime": {
"date": 20,
"day": 5,
"hours": 0,
"minutes": 0,
"month": 1,
"seconds": 0,
"time": 1424370600000,
"timezoneOffset": -330,
"year": 115
}
};
document.getElementById("demo").innerHTML = new Date(json.endTime.time).toLocaleFormat("%Y-%m-%d");
这篇关于日期格式如何转换为 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文