You are on page 1of 1

// to change the time to Indian Standard Time (IST)

// let date = new Date("2023-09-21T05:22:15.693+00:00")


// date.setHours(date.getHours() + 5);
// date.setMinutes(date.getMinutes() + 30);
// const formattedDate = date.toISOString();
// console.log(formattedDate); // 2023-09-21T10:52:15.693Z

// or
const date = new Date('2023-09-21T05:22:15.693+00:00');
const ist = date.toLocaleString('en-US', { timeZone: 'Asia/Kolkata' });

console.log(ist); // 9/21/2023, 10:52:15 AM

// Get current indian date and time;


// get the current time and add 5hrs and 30 min in that time

// let currentDate = new Date()


// currentDate.setHours(currentDate.getHours() + 5);
// currentDate.setMinutes(currentDate.getMinutes() + 30);
// const formattedDate = currentDate.toISOString();
// console.log(formattedDate);

// or
// const date = new Date();
// const ist = date.toLocaleString('en-US', { timeZone: 'Asia/Kolkata' });

// console.log(ist); // 9/21/2023, 10:52:15 AM

// or schema
// const yourSchema = new mongoose.Schema({
// yourField: {
// type: Date,
// default: function () {
// // Get the current date and time in the Indian time zone (+5:30 offset)
// const indianTime = new Date();
// indianTime.setHours(indianTime.getHours() + 5);
// indianTime.setMinutes(indianTime.getMinutes() + 30);
// return indianTime;
// },
// },

You might also like