Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Last active September 4, 2015 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornerymoose/54d04ef1c5da8c808ffa to your computer and use it in GitHub Desktop.
Save ornerymoose/54d04ef1c5da8c808ffa to your computer and use it in GitHub Desktop.
function getTimeStamp() {
var now = new Date();
return ((now.getMonth() + 1) + '-' + (now.getDate()) + '-' + now.getFullYear() + " " + now.getHours() + ':' + ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes())) + ':' + ((now.getSeconds() < 10) ? ("0" + now.getSeconds()) : (now.getSeconds())));
//in Chrome, this returns: Fri Sep 04 2015 14:10:50 GMT-0400 (EDT)
//in Firefox, this returns: Date 2015-09-04T18:11:08.322Z
}
//What's the correct way to get the Firefox one to display correctly? In the bigger picture, this is used in a ticketing system
//and the duration of the ticket is sent in an email.
//If the ticket is closed in Chrome, no problems: it shows the duration correctly.
//If the ticket is closed in Firefox, it returns NaN
millisToTime = function(ms){
x = ms / 1000;
seconds = Math.round(x % 60);
x /= 60;
minutes = Math.round(x % 60);
x /= 60;
hours = Math.round(x % 24);
x /= 24;
days = Math.round(x);
// return {"Days" : days, "Hours" : hours, "Minutes" : minutes, "Seconds" : seconds};
return days + " days, " + hours + " hours, " + minutes + " minutes, and " + seconds + " seconds";
}
$("#close-ticket").click(function(e){
e.preventDefault();
var gts_format = new Date(getTimeStamp());
var js_date = new Date("<?php echo $format_time_submitted; ?>");
var ticket_duration = (gts_format - js_date);
var ticket_duration_formatted = millisToTime(ticket_duration);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment