I would like to extract the year from the current date using Python.
In C#, this looks like:
DateTime a = DateTime.Now()
a.Year
What is required in Python?
解决方案
It's in fact almost the same in Python.. :-)
import datetime
year = datetime.date.today().year
Of course, date doesn't have a time associated, so if you care about that too, you can do the same with a complete datetime object:
import datetime
year = datetime.datetime.today().year
(Obviously no different, but you can store datetime.datetime.today() in a variable before you grab the year, of course).
One key thing to note is that the time components can differ between 32-bit and 64-bit pythons in some python versions (2.5.x tree I think). So you will find things like hour/min/sec on some 64-bit platforms, while you get hour/minute/second on 32-bit.
python 日志 提取 May 26 00:34:17日期 python提取一个日期中的年份
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:java语言词法分析器的设计与实现 词法分析代码实现
下一篇:hive 新增Concurrency mode is disabled, not creating a lock manager hive 新增行

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章