Javascript Convert Date Time string to Epoch

后端 未结 8 854
攒了一身酷
攒了一身酷 2020-11-30 09:46

so I give up...been trying to do this all day;

I have a string that supplies a date and time in the format dd/MM/yyyy hh:mm (04/12/2012 07:00

8条回答
  •  悲哀的现实
    2020-11-30 10:11

    var time = new Date().getTime() / 1000 + 900 + 330*60;
    
    console.log("time = "+time);
    

    getTime() will return current time with milleseconds in last 3 digit so divide it by 1000 first. Now I have added 900 means 15 min which I need from my current time(You can delete if you do not require further delay time), 330*60(5 hr 30) is required to convert GMT time to IST which is my current region time.

    Use below site to test your time :-

    https://www.epochconverter.com/

    Hope it will help you :)

提交回复
热议问题