python date time in javascript

To perform date and time operations in JavaScript similar to Python, you can use the moment.js library. Below is an example of how you can perform date and time operations in JavaScript using moment.js library:

index.tsx
// Install moment.js via npm or include it via CDN

// Parse a date and time string
var datetimeString = "2023-04-12 14:30:00";
var parsedDate = moment(datetimeString, "YYYY-MM-DD HH:mm:ss");

// Format a date
var formattedDate = parsedDate.format("dddd, MMMM Do YYYY, h:mm:ss a");

// Add days
var newDate = parsedDate.add(7, 'days');

// Subtract hours
var newTime = parsedDate.subtract(3, 'hours');
402 chars
15 lines

Remember to include the moment.js library in your HTML file.

related categories

gistlibby LogSnag