How to get current time and date in C++?

Since C++ 11 you can use std::chrono::system_clock::now() Example (copied from en.cppreference.com): #include <iostream> #include <chrono> #include <ctime> int main() { auto start = std::chrono::system_clock::now(); // Some computation here auto end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_seconds = end-start; std::time_t end_time = std::chrono::system_clock::to_time_t(end); std::cout << “finished computation at ” << std::ctime(&end_time) << “elapsed time: ” << elapsed_seconds.count() << … Read more

How do I measure execution time of a command on the Windows command line?

PowerShell has a cmdlet for this called Measure-Command. You’ll have to ensure that PowerShell is available on the machine that runs it. PS> Measure-Command { echo hi } Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 0 Ticks : 1318 TotalDays : 1.52546296296296E-09 TotalHours : 3.66111111111111E-08 TotalMinutes : 2.19666666666667E-06 … Read more

What is this date format? 2011-08-12T20:17:46.384Z

The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC). If your strings always have a “Z” you can use: SimpleDateFormat format = new SimpleDateFormat( “yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”, Locale.US); format.setTimeZone(TimeZone.getTimeZone(“UTC”)); Or using Joda Time, you can use ISODateTimeFormat.dateTime().

How to convert Milliseconds to “X mins, x seconds” in Java?

Use the java.util.concurrent.TimeUnit class: String.format(“%d min, %d sec”, TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) – TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) ); Note: TimeUnit is part of the Java 1.5 specification, but toMinutes was added as of Java 1.6. To add a leading zero for values 0-9, just do: String.format(“%02d min, %02d sec”, TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) – TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) ); If TimeUnit or toMinutes are unsupported … Read more

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