What is better coding javascript for set two range of Datetime?


What is better coding javascript for set two range of Datetime?



I have a given data formatted as follows and is a string.


var str = "28/06/2018|11:54:15";



I need to convert it to DateTime and create two new strings date with an interval of 20 seconds before and 20 seconds after the start date.


var startTime = year1 + "-" + month1 + "-" + day1 + " " + hour1 + ":" + minute1 + ":" + second1;
var endTime = year2 + "-" + month2 + "-" + day2 + " " + hour2 + ":" + minute2 + ":" + second2;



The result, in this case, will be


startTime = "2018-06-28|11:53:55";
endTime = "2018-06-28|11:54:35";



I try to split str, but I don't think it's the best solution.



Can you help me? Thank you.





"I try to split str, but I don't think it's the best solution" Yes, that's certainly a perfectly valid (and fairly simple) approach. You could also use a regular expression. Your best bet here is to do your research, search for related topics on SO, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a Minimal, Complete, and Verifiable example of your attempt and say specifically where you're stuck. People will be glad to help. Good luck!
– T.J. Crowder
Jun 29 at 10:10









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined