我正在尝试运行以下代码:
// Included the data time formatter
var DateTimeFormatter = require('datetimeformatter');
var inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
var outputFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
var date = LocalDate.parse(gDate, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
var formattedDate = outputFormatter.format(date);
Console.out(formattedDate);
当我运行代码时,我得到以下TypeError: DateTimeFormatter.ofPattern is not a function
从网上搜索的不准确,模式应该是一个函数!?
我做错了什么?
尝试此命令:
npm install date-and-time
示例用法:
const date = require('date-and-time')
const bd = new Date();
const value = date.format(bd,'YYYY/MM/DD HH:mm:ss');
console.log("current date and time : " + value)
包含的代码似乎表明您正在尝试运行Java代码。您可以提取日期字符串,例如:
const newTime = new Date('2022-09-09T00:20Z').toLocaleDateString('en-gb');
您可以对输出结果进行更多修改,例如:`
const newTime = new Date('2019-02-19T06:00:00Z').toLocaleDateString('en-gb' {
year: 'numeric',
month: 'long',
day: 'numeric'
}); // 18 February 2019`