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
628
votes
26 answers

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

Is there a cross-platform way to get the current date and time in C++?
Max Frai
  • 61,946
  • 78
  • 197
  • 306
626
votes
13 answers

how to sort pandas dataframe from one column

I have a data frame like this: print(df) 0 1 2 0 354.7 April 4.0 1 55.4 August 8.0 2 176.5 December 12.0 3 95.5 February 2.0 4 85.6 January 1.0 5 152 July 7.0 6 238.7 …
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
574
votes
12 answers

Algorithm to detect overlapping periods

I've to detect if two time periods are overlapping. Every period has a start date and an end date. I need to detect if my first time period (A) is overlapping with another one(B/C). In my case, if the start of B is equal to the end of A, they are…
J4N
  • 19,480
  • 39
  • 187
  • 340
569
votes
20 answers

NOW() function in PHP

Is there a PHP function that returns the date and time in the same format as the MySQL function NOW()? I know how to do it using date(), but I am asking if there is a function only for this. For example, to return: 2009-12-01 00:00:00
MoeAmine
  • 5,976
  • 2
  • 18
  • 21
553
votes
22 answers

How to recursively find and list the latest modified files in a directory with subdirectories and times

Operating system: Linux Filesystem type: ext3 Preferred solution: Bash (script/one-liner), Ruby, or Python I have several directories with several subdirectories and files in them. I need to make a list of all these directories that is…
fredrik
  • 5,655
  • 3
  • 15
  • 7
519
votes
5 answers

Why is 1/1/1970 the "epoch time"?

Why is 1 January 1970 00:00:00 considered the epoch time?
rahul
  • 184,426
  • 49
  • 232
  • 263
517
votes
11 answers

What is the standard way to add N seconds to datetime.time in Python?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example? These obvious ideas don't work: >>> datetime.time(11, 34, 59) + 3 TypeError: unsupported operand…
Paul Stephenson
  • 67,682
  • 9
  • 49
  • 51
498
votes
46 answers

Calculating the difference between two Java date instances

I'm using Java's java.util.Date class in Scala and want to compare a Date object and the current time. I know I can calculate the delta by using getTime(): (new java.util.Date()).getTime() - oldDate.getTime() However, this just leaves me with a…
pr1001
  • 21,727
  • 17
  • 79
  • 125
483
votes
33 answers

How do you display JavaScript datetime in 12 hour AM/PM format?

How do you display a JavaScript datetime object in the 12 hour format (AM/PM)?
bbrame
  • 18,031
  • 10
  • 35
  • 52
483
votes
14 answers

How do you convert epoch time in C#?

How do you convert Unix epoch time into real time in C#? (Epoch beginning 1/1/1970)
hsatterwhite
  • 7,160
  • 5
  • 26
  • 29
483
votes
9 answers

How to multiply duration by integer?

To test concurrent goroutines, I added a line to a function to make it take a random time to return (up to one second) time.Sleep(rand.Int31n(1000) * time.Millisecond) However when I compiled, I got this error .\crawler.go:49: invalid operation:…
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
462
votes
15 answers

How to use timeit module

How do I use timeit to compare the performance of my own functions such as "insertion_sort" and "tim_sort"?
Neemaximo
  • 20,031
  • 12
  • 32
  • 40
461
votes
3 answers

In Ruby on Rails, what's the difference between DateTime, Timestamp, Time and Date?

In my experience, getting dates/times right when programming is always fraught with danger and difficulity. Ruby and Rails have always eluded me on this one, if only due to the overwhelming number of options; I never have any idea which I should…
Nick
  • 4,765
  • 3
  • 17
  • 9
454
votes
16 answers

Python's time.clock() vs. time.time() accuracy?

Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy? for example: start = time.clock() ... do something elapsed = (time.clock() - start) vs. start = time.time() ... do something elapsed =…
Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
454
votes
10 answers

How to get current time in python and break up into year, month, day, hour, minute?

I would like to get the current time in Python and assign them into variables like year, month, day, hour, minute. How can this be done in Python 2.7?
guagay_wk
  • 26,337
  • 54
  • 186
  • 295