Print time in 15-minute increments between two times in the same day

it can also be done with the range function <?php date_default_timezone_set(“Europe/London”); $range=range(strtotime(“08:00”),strtotime(“17:00”),15*60); foreach($range as $time){ echo date(“H:i”,$time).”\n”; } ?> so you don’t have a loop, it just makes an array for you (my loop is just to print it out whilst formatting it)

Javascript: convert 24-hour time-of-day string to 12-hour time with AM/PM and no timezone

Nothing built in, my solution would be as follows : function tConvert (time) { // Check correct time format and split into components time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time]; if (time.length > 1) { // If time format correct time = time.slice (1); // Remove full string match value time[5] = +time[0] < 12 … Read more

How to convert milliseconds to “hh:mm:ss” format?

You were really close: String.format(“%02d:%02d:%02d”, TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) – TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), // The change is in this line TimeUnit.MILLISECONDS.toSeconds(millis) – TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); You were converting hours to millisseconds using minutes instead of hours. BTW, I like your use of the TimeUnit API 🙂 Here’s some test code: public static void main(String[] args) throws ParseException { long millis = … Read more

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

tech