I have a request from angular, which sends date to server.
const activationDate = new Date();
I need to convert this to UTC date format before sending the request
In my model, I have a Date variable to pass the date to server
export class PersonDetails {
id: string;
activationDate?: Date;
}
personModel: PersonDetail;
const activationDate = new Date();
this.personModel.activationDate = new Date(activationDate.getUTCFullYear(),
activationDate.getUTCMonth(),
activationDate.getUTCDate(),
activationDate.getUTCHours(),
activationDate.getUTCMinutes(),
activationDate.getUTCSeconds()
);
OR Can use a separate method to get UTCDate
const activationDate = this.getNowUTC();
private getNowUTC() {
const now = new Date();
return new Date(now.getTime() + (now.getTimezoneOffset() * 60000));
}
A good article on converting DateTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With