从日期转换为ISO字符串中删除秒/毫秒 [英] Remove Seconds/ Milliseconds from Date convert to ISO String
本文介绍了从日期转换为ISO字符串中删除秒/毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个我想要的日期对象
I have a date object that I want to
- 删除miliseconds /或设置为0
- 删除秒数/或设置为0
- 转换为ISO字符串
例如:
var date = new Date();
//Wed Mar 02 2016 16:54:13 GMT-0500 (EST)
var stringDate = moment(date).toISOString();
//2016-03-02T21:54:13.537Z
但我真正想要的是什么最后是
But what I really want in the end is
stringDate = '2016-03-02T21:54:00.000Z'
推荐答案
虽然这很容易用普通的javascript解决(请参阅RobG的回答),但我想告诉你自从您将问题标记为 momentjs
:
While this is easily solvable with plain javascript (see RobG's answer), I wanted to show you the momentjs solution since you tagged your questions as momentjs
:
moment().seconds(0).milliseconds(0).toISOString();
这为您提供了当前的日期时间,没有秒或毫秒。
This gives you the current datetime, without seconds or milliseconds.
工作示例: http://jsbin.com/bemalapuyi/edit ?html,js,output
来自文档: http://momentjs.com/docs/#/get-set/
这篇关于从日期转换为ISO字符串中删除秒/毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文