time interview questions
Top time frequently asked interview questions
I need to convert seconds to Hour:Minute:Second.
For example: 685 converted to 00:11:25
How can I achieve this?
Source: (StackOverflow)
I'm creating a web based system which will be used in countries from all over the world. One type of data which must be stored is dates and times.
What are the pros and cons of using the Java date and time classes compared to 3rd party libraries such as Joda time? I guess these third party libraries exist for a good reason, but I've never really compared them myself.
Source: (StackOverflow)
$ time foo
real 0m0.003s
user 0m0.000s
sys 0m0.004s
Which of these three is meaningful when benchmarking my app?
Source: (StackOverflow)
Can somebody recommend the best way to convert a string in the format 'January 2, 2010' to a date in java? Ultimately, I want to break out the month, the day, and the year as integers so that I can use:
Date date = new Date();
date.setMonth()..
date.setYear()..
date.setDay()..
date.setlong currentTime = date.getTime();
to convert the date into time.
Source: (StackOverflow)
I want to record the time using System.currentTimeMillis()
when a user begins something in my program. When he finishes, I will subtract the current System.currentTimeMillis()
from the start
variable, and I want to show them the time elapsed using a human readable format such as "XX hours, XX mins, XX seconds" or even "XX mins, XX seconds" because its not likely to take someone an hour.
What's the best way to do this?
Source: (StackOverflow)
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 pick.
When I'm using Rails and looking at ActiveRecord datatypes I can find the following
:datetime, :timestamp, :time, and :date
and have no idea what the differences are or where the gotchas lurk.
What's the difference? What do you use them for?
(P.S. I'm using Rails3)
Source: (StackOverflow)
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 type(s) for +: 'datetime.time' and 'int'
>>> datetime.time(11, 34, 59) + datetime.timedelta(0, 3)
TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta'
>>> datetime.time(11, 34, 59) + datetime.time(0, 0, 3)
TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.time'
In the end I have written functions like this:
def add_secs_to_time(timeval, secs_to_add):
secs = timeval.hour * 3600 + timeval.minute * 60 + timeval.second
secs += secs_to_add
return datetime.time(secs // 3600, (secs % 3600) // 60, secs % 60)
I can't help thinking that I'm missing an easier way to do this though.
Related
Source: (StackOverflow)
I understand the concept of what timeit
does but I am not sure how to implement it in my code.
How can I compare two functions, say insertion_sort
and tim_sort
, with timeit
?
Source: (StackOverflow)