Convert seconds to HH-MM-SS with JavaScript?

You can manage to do this without any external JavaScript library with the help of JavaScript Date method like following: var date = new Date(null); date.setSeconds(SECONDS); // specify value for SECONDS here var result = date.toISOString().substr(11, 8); Or, as per @Frank’s comment; a one liner: new Date(SECONDS * 1000).toISOString().substr(11, 8);

JavaScript seconds to time string with format hh:mm:ss

String.prototype.toHHMMSS = function () { var sec_num = parseInt(this, 10); // don’t forget the second param var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num – (hours * 3600)) / 60); var seconds = sec_num – (hours * 3600) – (minutes * 60); if (hours < 10) {hours = “0”+hours;} if (minutes < 10) … Read more

Javascript add leading zeroes to date

Try this: http://jsfiddle.net/xA5B7/ var MyDate = new Date(); var MyDateString; MyDate.setDate(MyDate.getDate() + 20); MyDateString = (‘0’ + MyDate.getDate()).slice(-2) + “https://stackoverflow.com/” + (‘0’ + (MyDate.getMonth()+1)).slice(-2) + “https://stackoverflow.com/” + MyDate.getFullYear(); EDIT: To explain, .slice(-2) gives us the last two characters of the string. So no matter what, we can add “0” to the day or month, and … Read more

Get month name from Date

Shorter version: const monthNames = [“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December” ]; const d = new Date(); document.write(“The current month is ” + monthNames[d.getMonth()]); Note (2019-03-08) – This answer by me which I originally wrote in 2009 is outdated. See David Storey’s answer for a better solution.

Where can I find documentation on formatting a date in JavaScript?

I love 10 ways to format time and date using JavaScript and Working with Dates. Basically, you have three methods and you have to combine the strings for yourself: getDate() // Returns the date getMonth() // Returns the month getFullYear() // Returns the year Example: var d = new Date(); var curr_date = d.getDate(); var … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)