time-format
/usr/bin/time –format output elapsed time in milliseconds
One possibility is to use the date command: ts=$(date +%s%N) ; my_command ; tt=$((($(date +%s%N) – $ts)/1000000)) ; echo “Time taken: $tt milliseconds” %N should return nanoseconds, and 1 millisecond is 1000000 nanosecond, hence by division would return the time taken to execute my_command in milliseconds. NOTE that the %N is not supported on all … Read more
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
Getting Hour and Minute in PHP
print date(‘H:i’); $var = date(‘H:i’); Should do it, for the current time. Use a lower case h for 12 hour clock instead of 24 hour. More date time formats listed here.
How to display a date as iso 8601 format with PHP
The second argument of date is a UNIX timestamp, not a database timestamp string. You need to convert your database timestamp with strtotime. <?= date(“c”, strtotime($post[3])) ?>
PHP Timestamp into DateTime
You don’t need to turn the string into a timestamp in order to create the DateTime object (in fact, its constructor doesn’t even allow you to do this, as you can tell). You can simply feed your date string into the DateTime constructor as-is: // Assuming $item->pubDate is “Mon, 12 Dec 2011 21:17:52 +0000” $dt … Read more
How do I convert datetime to ISO 8601 in PHP
Object Oriented This is the recommended way. $datetime = new DateTime(‘2010-12-30 23:21:46’); echo $datetime->format(DateTime::ATOM); // Updated ISO8601 Procedural For older versions of PHP, or if you are more comfortable with procedural code. echo date(DATE_ISO8601, strtotime(‘2010-12-30 23:21:46’));
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