Issue
How to get time difference only:
My Code:
const date = moment.utc().format();
const localtime = moment.utc(date).local.format(); // 2022-07-01t18:53:00 +05:30
how can I get only difference +05:30 from localtime I only need time difference I don't want entire date(2022-07-01t18:53:00)
Kindly help
Solution
const localtime = moment.utc(date).local.utcOffset(); // This will be minutes
const localHours = Math.floor(localtime/60);
const localMinutes = localtime - localHours*60;
const localOffset = (localHours>0?"+":"") + localHours+":"+localMinutes;
Get the offset from the moment date, it will be in minutes, so you convert to hours and minutes. Then you add the + sign if it is positive.
Answered By - Salketer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.