473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

datetime.datetime.now() in military time

import datetime

def main():
timenow = datetime.datetime.now()
print(str(timenow.hour))
if __name__ == "__main__":
main()

If the time was, say, 2pm, how can I make output of timenow.hour "14"
instead of "2"?

Thanks.
-Dave
Aug 19 '08 #1
1 8996
On Aug 19, 10:42*am, korean_dave <davidrey...@gmail.comwrote:
import datetime

def main():
* * timenow = datetime.datetime.now()
* * print(str(timenow.hour))

if __name__ == "__main__":
* * main()

If the time was, say, 2pm, how can I make output of timenow.hour "14"
instead of "2"?

Thanks.
-Dave
Use the strftime() method to convert the time. Something like this:

print timenow.strftime('%H')

See also: http://docs.python.org/lib/module-time.html

Mike
Aug 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
1
by: Doug Swanson | last post by:
I have some questions about datetime formatting....In our web app I have the following in the web.config <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US"...
1
by: Sandy | last post by:
Hello - I had originally posted this question and was told the problem was caused by a setting on the host and could not be changed there. I called the host to see if they knew how I can solve...
3
by: Eric Stott | last post by:
I need to take System.DateTime.Now and have the resulting text be in the following format: yyyyMMddhh24mmsss I am using System.Convert.ToString(System.DateTime.Now), but I need to format it...
8
by: Phillip Vong | last post by:
Simple question from a newbie. Using VWD in VB.NET for ASP.NET. I want to format a time value to show in military time only and without the seconds. I know it's not {0:t} or {0:T} but I can not...
6
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in...
11
by: Peter Holschbach | last post by:
Hi, I've the following line of code: result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); where I get in result "result" "02.12.1999...
0
by: lemnitzer | last post by:
Full Article: http://iamthewitness.com/FreedmanFactsAreFacts.html <-------- KEY DOCUMENT Steamy Excerpts: Will you be patient with me while I review here as briefly as I can the history of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.