EzDevInfo.com

time interview questions

Top time frequently asked interview questions

Get current time in milliseconds in Python?

How can I get the current time in milliseconds in Python?


Source: (StackOverflow)

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

Is there a cross-platform way to get the current date and time in C++?


Source: (StackOverflow)

Advertisements

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)


Source: (StackOverflow)

Does Python's time.time() return the local or UTC timestamp?

Does time.time() in the Python time module return the system's time or the time in UTC?


Source: (StackOverflow)

Convert seconds to Hour:Minute:Second

I need to convert seconds to Hour:Minute:Second.

For example: 685 converted to 00:11:25

How can I achieve this?


Source: (StackOverflow)

Should I use Java date and time classes or go with a 3rd party library like Joda Time?

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)

How to get current time in Python

What is the module/method used to get current time?


Source: (StackOverflow)

What do 'real', 'user' and 'sys' mean in the output of time(1)?

$ time foo
real        0m0.003s
user        0m0.000s
sys         0m0.004s

Which of these three is meaningful when benchmarking my app?


Source: (StackOverflow)

Get current time and date on Android

How can I get the current time and date in an Android app?


Source: (StackOverflow)

Java string to date conversion

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)

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

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 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 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)

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 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)

How to use timeit module

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)