-2

Wanna add dstOffset = "01:00:00" into the original time value 2020-05-16T21:17:34+00:00. Orginal time value is converted into EPOCH and it is now 1589663854. I need to convert that dstOffset in EPOCH like in number '1589663854'etc and add it in orginal time. Thanks.

Abdul Moeez
  • 1,331
  • 2
  • 13
  • 31
  • 1
    Epoch time is a full date and time, not just a time. Are you asking about the time assuming today's date? Also take a look at the moment package on npmjs.com. https://www.npmjs.com/package/moment – Always Learning May 07 '20 at 22:59
  • 1
    You can find the answer easily if you search. Check this: https://stackoverflow.com/questions/13707333/javascript-convert-date-time-string-to-epoch – Yagiz Turkmen May 07 '20 at 23:01

1 Answers1

1

You can do this using the built in Javascript Date function. If you want to use todays date, you can get the current date and set the time to the original time you mentioned. Here is an example:

var originalFormat = '01:02:03';

// get todays date
var time = new Date();

// set the correct time
var timeValues = originalFormat.split(':').map((element) => Number(element));
time.setHours(timeValues[0], timeValues[1], timeValues[2]);
console.log('correct time values:', time.toString());

// get epoch value
var epoch = time.valueOf();
console.log('epoch:', epoch);
jjgg
  • 630
  • 5
  • 15