Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

i can able to convert the current date and time in seconds by using time.time() like now = datetime.datetime.now() now = time.time(). print("the now time is") + str(now)

Output the now time is 1340867411.88

is there any command to change this "1340867411.88" to current date time format?

Thanks,

share|improve this question
3  
Please take a moment to look at your previous questions and accept the answers (tick mark on the left), if they solved your problem. This way the question is marked as "answered", and the community can rely on the solution in the future, knowing it works. – izx Jun 28 '12 at 7:16

closed as off topic by izx, James Henstridge, jokerdino, ajmitch, Martin Owens -doctormo- Aug 18 '12 at 2:14

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

From the looks of your code I assume that you are using this for a python script. Because of this, we'll have to proceed this way:

 import time
 now = time.ctime(int(time.time()))
 print("the now time is ") + str(now)

Which, using your example timestamp, should give you the following output:

 Thu, 28 Jun 2012 07:10:11 GMT

However, I would just go ahead and use ctime instead of time to avoid having to convert the timestamp.

If you'd like only the time, you could use this approach instead:

 import time
 now = time.strftime("%H:%M", time.localtime(time.time()))
 print("the now time is ") + str(now)
share|improve this answer
thank you very much, it is very useful to me and i satisfied now because of i learn one new thing today. – Viswa Jun 28 '12 at 8:43
2  
Please mark the question as solved by clicking the tick-box to the left of my answer. – Simon Aronsson Jun 28 '12 at 11:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.