I have a unix timestamp: 1368435600. And a duration in minutes: 75 for example.
Using javascript I need to:
I tried the moment.js library:
end_time = moment(start_time).add('m', booking_service_duration);
booking_service_duration was 75 but it added an hour. I'd also rather not have to use another js library
The Unix timestamp is designed to track time as a running total of seconds from the Unix Epoch on January 1st, 1970 at UTC. To add 24 hours to a Unix timestamp we can use any of these methods: Method 1: Convert 24 hours to seconds and add the result to current Unix time. echo time() + (24*60*60);
You can use the Calendar class's add method to add specify time of date from seconds, minute, hours, etc. in Calendar's constant.
To get the unix timestamp using JavaScript you need to use the getTime() function of the build in Date object. As this returns the number of milliseconds then we must divide the number by 1000 and round it in order to get the timestamp in seconds. Math. round(new Date().
Unix time is the number of seconds that have elapsed since 1 January 1970 UTC.
To move that time forward you simply add the number of seconds.
So once you have the minutes, the new timestamp is oldTime + 60*minutes
For the conversion look up parsing libraries, there is code out there for this, do some research.
To add 75 minutes, just multiply by 60 to get the number of seconds, and add that to the timestamp:
timestamp += 75 * 60
To convert to hours:mins you will have to do a bit more math:
var hours = Math.floor(timestamp/60/60),
mins = Math.floor((timestamp - hours * 60 * 60) / 60),
output = hours%24+":"+mins;
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