I am trying to run the following code:
// 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);
System.out.println(formattedDate);
when I run the code i get the following TypeError: DateTimeFormatter.ofPattern is not a function
From searching online that is not accurate, ofPattern should be a function!?
What am I doing wrong?
CodePudding user response:
Try this command:
npm install date-and-time
Example usage:
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)
CodePudding user response:
Included code seems to suggest you are trying to run Java code. You can extract the date string for example:
const newTime = new Date('2022-09-09T00:20Z').toLocaleDateString('en-gb');
You can modify the output result more, for example: `
const newTime = new Date('2019-02-19T06:00:00Z').toLocaleDateString('en-gb' {
year: 'numeric',
month: 'long',
day: 'numeric'
}); // 18 February 2019`