nsn-util
Version:
NSN工具辅助组件
35 lines (30 loc) • 700 B
JavaScript
import moment from 'moment';
import * as NStr from './NStr'; // 关闭警告提示
moment.suppressDeprecationWarnings = true;
/**
* 获取日期
*
* @param str 需要格式化的日期格式字符串
* @returns 字符串未定义时,返回当前日期
*/
var now = function now(str) {
if (NStr.isEmpty(str)) {
return get(moment());
}
return get(moment(str));
};
var get = function get(now) {
var text = now.format('YYYY 年 MM 月 DD 日');
var value = now.format('YYYY-MM-DD');
var year = now.year();
var month = now.month() + 1;
var day = now.date();
return {
text: text,
value: value,
year: year,
month: month,
day: day
};
};
export { now };