Questions tagged [time]

Measuring the time it takes to perform an operation. Also, questions related to obtaining the current time, calculating on times, formatting and parsing times, etc.

Measuring the time it takes to perform an operation. Also, questions related to obtaining the current time, calculating on times, formatting and parsing times, etc. See also and .

For analysis in , consider looking at the Time Series Task View.

29686 questions
331
votes
10 answers

What is the easiest way to get current GMT time in Unix timestamp format?

Python provides different packages (datetime, time, calendar) as can be seen here in order to deal with time. I made a big mistake by using the following to get current GMT time time.mktime(datetime.datetime.utcnow().timetuple()) What is a simple…
Cory
  • 14,865
  • 24
  • 57
  • 72
322
votes
4 answers

Get a UTC timestamp

How can I get the current UTC timestamp in JavaScript? I want to do this so I can send timestamps from the client-side that are independent of their timezone.
Ben G
  • 26,091
  • 34
  • 103
  • 170
319
votes
10 answers

Timing a command's execution in PowerShell

Is there a simple way to time the execution of a command in PowerShell, like the 'time' command in Linux? I came up with this: $s=Get-Date; .\do_something.ps1 ; $e=Get-Date; ($e - $s).TotalSeconds But I would like something simpler like time…
Paolo Tedesco
  • 55,237
  • 33
  • 144
  • 193
308
votes
32 answers

Displaying the build date

I currently have an app displaying the build number in its title window. That's well and good except it means nothing to most of the users, who want to know if they have the latest build - they tend to refer to it as "last Thursday's" rather than…
Mark Mayo
  • 12,230
  • 12
  • 54
  • 85
290
votes
15 answers

How do I use .toLocaleTimeString() without displaying seconds?

I'm currently attempting to display the user's time without displaying the seconds. Is there a way I can do this using Javascript's .toLocaleTimeString()? Doing something like this: var date = new Date(); var string =…
javadog36
  • 3,025
  • 2
  • 13
  • 7
288
votes
7 answers

How do I check the difference, in seconds, between two dates?

There has to be an easier way to do this. I have objects that want to be refreshed every so often, so I want to record when they were created, check against the current timestamp, and refresh as necessary. datetime.datetime has proven to be…
alexgolec
  • 26,898
  • 33
  • 107
  • 159
282
votes
11 answers

How do I represent a time only value in .NET?

Is there a way one can represent a time only value in .NET without the date? For example, indicating the opening time of a shop? TimeSpan indicates a range, whereas I only want to store a time value. Using DateTime to indicate this would result in…
sduplooy
  • 14,340
  • 9
  • 41
  • 60
282
votes
22 answers

Get the time difference between two datetimes

I know I can do anything and some more envolving Dates with momentjs. But embarrassingly, I'm having a hard time trying to do something that seems simple: geting the difference between 2 times. Example: var now = "04/09/2013 15:00:00"; var then =…
Leo
  • 7,379
  • 6
  • 28
  • 44
282
votes
4 answers

Python datetime - setting fixed hour and minute after using strptime to get day,month,year

I've successfully converted something of 26 Sep 2012 format to 26-09-2012 using: datetime.strptime(request.POST['sample_date'],'%d %b %Y') However, I don't know how to set the hour and minute of something like the above to 11:59. Does anyone know…
user1678031
  • 2,925
  • 2
  • 16
  • 15
275
votes
25 answers

How to convert date to timestamp?

I want to convert date to timestamp, my input is 26-02-2012. I used new Date(myDate).getTime(); It says NaN.. Can any one tell how to convert this?
selladurai
  • 6,491
  • 14
  • 56
  • 88
273
votes
12 answers

How to redirect the output of the time command to a file in Linux?

Just a little question about timing programs on Linux: the time command allows to measure the execution time of a program: [ed@lbox200 ~]$ time sleep 1 real 0m1.004s user 0m0.000s sys 0m0.004s Which works fine. But if I try to redirect…
ed82
  • 3,007
  • 3
  • 15
  • 11
270
votes
8 answers

Difference between CLOCK_REALTIME and CLOCK_MONOTONIC?

Could you explain the difference between CLOCK_REALTIME and CLOCK_MONOTONIC clocks returned by clock_gettime() on Linux? Which is a better choice if I need to compute elapsed time between timestamps produced by an external source and the current…
NPE
  • 486,780
  • 108
  • 951
  • 1,012
267
votes
4 answers

What is the `zero` value for time.Time in Go?

In an error condition, I tried to return nil, which throws the error: cannot use nil as type time.Time in return argument What is the zero value for time.Time?
Mingyu
  • 31,751
  • 14
  • 55
  • 60
266
votes
16 answers

Python logging: use milliseconds in time format

By default logging.Formatter('%(asctime)s') prints with the following format: 2011-06-09 10:54:40,638 where 638 is the millisecond. I need to change the comma to a dot: 2011-06-09 10:54:40.638 To format the time I can…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
263
votes
8 answers

System.currentTimeMillis() vs. new Date() vs. Calendar.getInstance().getTime()

In Java, what are the performance and resource implications of using System.currentTimeMillis() vs. new Date() vs. Calendar.getInstance().getTime() As I understand it, System.currentTimeMillis() is the most efficient. However, in most…
Vihung
  • 12,947
  • 16
  • 64
  • 90