简体   繁体   English

通过使用moment.Js通过提供用户定义的时间值来创建当前日期和时间

[英]using moment.Js to create current date and time by giving user defined values for time

Suppose I gave a value as 4:30 I then split them into something like this ['4' , '30']. 假设我给了一个4:30的值,然后将它们拆分成类似[[4','30']的内容。 I want to use moment to format it into something like this moment("2010-10-20 4:30", "YYYY-MM-DD HH:mm"); 我想使用一下矩将其格式化为类似当前矩的格式(“ 2010-10-20 4:30”,“ YYYY-MM-DD HH:mm”); // parsed as 4:30 localtime any clues..? //有任何线索解析为当地时间4:30?

here the date will be todays date. 这里的日期将是今天的日期。

You can achieve this by 您可以通过实现

var moment = require('moment')
moment("2010-10-20 04:30").format("YYYY-MM-DD HH:mm"); // will produce '2010-10-20 04:30'

More format examples: 更多格式示例:

moment().format('MMMM Do YYYY, h:mm:ss a'); // November 9th 2016, 11:47:05 am
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Nov 9th 16
moment().format('YYYY [escaped] YYYY');     // 2016 escaped 2016
moment().format();                          // 2016-11-09T11:47:05+01:00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM