time
Subtracting a certain number of hours, days, months or years from date
For hours: function get_offset_hours($hours) { return date(‘Y-m-d H:i:s’, time() + 3600 * $hours); } Something like that will work well for hours and days (use 86400 for days), but for months and year it’s a bit trickier… Also you can also do it this way: $date = strtotime(date(‘Y-m-d H:i:s’) . ‘ +1 day’); $date = … Read more
time format in SQL Server
You can use a combination of CONVERT, RIGHT and TRIM to get the desired result: SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7)) The 100 you see in the function specifies the date format mon dd yyyy hh:miAM (or PM), and from there we just grab the right characters. You can see more about converting datetimes here.
CPU execution time in Java
System.currentTimeMillis() will only ever measure wall-clock time, never CPU time. If you need wall-clock time, then System.nanoTime() is often more precise (and never worse) than currentTimeMillis(). ThreadMXBean.getThreadCPUTime() can help you find out how much CPU time a given thread has used. Use ManagementFactory.getThreadMXBean() to get a ThreadMXBean and Thread.getId() to find the id of the … Read more
Calculating Future Epoch Time in C#
There is an interesting twist when you want to know the Unix Epoch time in .Net on a Windows system. For nearly all practical cases and assuming the current time is past the Unix Epoch you could indeed take System.TimeSpan timeDifference = DateTime.UTCNow – new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); long unixEpochTime = … Read more
print current date in java
Your class is a custom class that is producing the output given by Object.toString. Rename the class to something else other than Date so that java.util.Date is correctly imported
How to convert a time into epoch time?
Use the mktime(3) function. For example: struct tm t = {0}; // Initalize to all 0’s t.tm_year = 112; // This is year-1900, so 112 = 2012 t.tm_mon = 8; t.tm_mday = 15; t.tm_hour = 21; t.tm_min = 54; t.tm_sec = 13; time_t timeSinceEpoch = mktime(&t); // Result: 1347764053
Sync Android devices via GPS time?
You can get the time difference in milliseconds from currentTimeMillis() and Location.getTime() in the onLocationChanged() callback. Use requestSingleUpdate() I just want to add that, if the user has a data connection they can use NTP time, which is even more accurate, as the GPS internal clock might drift and correcting it takes a while. EDIT: … Read more
How can I measure time with microsecond precision in Java?
My guess is that since System.nanoTime() uses the “most precise available system timer” which apparently only has millisecond-precision on your system, you can’t get anything better.
How can I calculate the number of days between two dates in Perl?
There seems to be quite a bit of confusion because, depending on what you are trying to accomplish, “the number of days between two dates” can mean at least two different things: The calendar distance between the two dates. The absolute distance between the two dates. As an example and to note the difference, assume … Read more