简体   繁体   English

我无法从 SugarJS 格式化日期

[英]I can't format date from SugarJS

I've tried using new module for my project, SugarJS.我已经尝试为我的项目 SugarJS 使用新模块。 I can print the date, but can't format it.我可以打印日期,但无法格式化。 Here is my code这是我的代码

const Sugar = require('sugar')

let yesterday = Sugar.Date.create()
let yesterdayWithFormat = Sugar.Date.create().format("{dd}")

yesterday output is 2019-10-14T06:52:28.466Z but yesterdayWithFormat error Sugar.Date.create(...).format is not a function昨天 output 是2019-10-14T06:52:28.466Z但昨天WithFormat 错误Sugar.Date.create(...).format is not a function

anyone can help me?任何人都可以帮助我吗?

To use format functions you need to call Sugar.extend();要使用format函数,您需要调用Sugar.extend(); :

const Sugar = require('sugar')

Sugar.extend();

let yesterday = Sugar.Date.create()
let yesterdayWithFormat = Sugar.Date.create().format("{dd}")

console.log(yesterday)
console.log(yesterdayWithFormat)

Using extend is optional as the same can be done with default setup.使用extend是可选的,因为default设置也可以这样做。 Try this尝试这个

const Sugar = require('sugar')

let yesterday = Sugar.Date.create()
let yesterdayWithFormat = Sugar.Date.format(yesterday, '{dd}');

You are trying to extend format from create which seems to be not available.您正在尝试从create扩展format ,这似乎不可用。

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

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