I'm using node-datetime library. I want to get current datetime with format such as Year-month-day hour-minute-second
我用node-datetime图书馆。我想获得当前的datetime,格式为Year-month-day -minute-second
ex : 2016-07-04 17:19:11
例:2016-07-04 17:19:11
var dateTime = require('node-datetime');
var dt = dateTime.create();
dt.format('m/d/Y H:M:S');
console.log(new Date(dt.now()));
But my result such as:
但我的结果是:
Mon Jul 04 2016 17:19:11 GMT+0700 (SE Asia Standard Time)
2016年7月04日星期一17:19:11 GMT+0700(东南亚标准时间)
1 个解决方案
#1
26
See the docs for details on format
:
详情请参阅文件:
Returns a formatted date time string.
返回格式化的日期时间字符串。
Store the result of your call to dt.format
and don't pass this to the Date
constructor:
将调用的结果存储到dt。格式化并不要将其传递给日期构造函数:
var dateTime = require('node-datetime');
var dt = dateTime.create();
var formatted = dt.format('Y-m-d H:M:S');
console.log(formatted);
I have amended the format string from 'm/d/Y'
to 'Y-m-d'
as per your question.
我已经根据你的问题将格式字符串从'm/d/Y'修改为'Y-m-d'。
#1
26
See the docs for details on format
:
详情请参阅文件:
Returns a formatted date time string.
返回格式化的日期时间字符串。
Store the result of your call to dt.format
and don't pass this to the Date
constructor:
将调用的结果存储到dt。格式化并不要将其传递给日期构造函数:
var dateTime = require('node-datetime');
var dt = dateTime.create();
var formatted = dt.format('Y-m-d H:M:S');
console.log(formatted);
I have amended the format string from 'm/d/Y'
to 'Y-m-d'
as per your question.
我已经根据你的问题将格式字符串从'm/d/Y'修改为'Y-m-d'。