[英]Js date format from google calendar event
I got event from google calendar and event has end time if format 2018-07-19T00:00:00+03:00 . 我从Google日历获取事件,并且事件的结束时间为格式2018-07-19T00:00:00 + 03:00 。 How can I get normal date from this?
我如何从中得到正常日期? Year, month, day, hour, minutes?
年,月,日,小时,分钟? Thanks.
谢谢。
you just need to use the Date
object of JavaScript : 您只需要使用JavaScript的
Date
对象:
let date = new Date('2018-07-19T00:00:00+03:00');
Here's the link to documentation : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date 这是文档的链接: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
This object as many method to get part of the date or to get representation of it. 此对象是获取部分日期或获取日期表示的许多方法。 As the documentation show in the example you can event do basic math beetween Dates
如示例中的文档所示,您可以在日期之间进行基本的数学运算
You can use moment
or date-fns
they are librairies to format dates. 您可以使用
moment
或date-fns
形式的fns来格式化日期。
Example: 例:
import moment from 'moment';
const day = moment('2018-07-19T00:00:00+03:00').format('DD');
if you are not using ES6/ES7, you can add the cdn to your project and use it the same way. 如果不使用ES6 / ES7,则可以将CDN添加到项目中,并以相同的方式使用它。
If you don't like using librairies, you can do it using js Date
. 如果您不喜欢使用库,则可以使用js
Date
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.