首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何创建基本的时间戳或日期?(Python 3.4)

如何创建基本的时间戳或日期?(Python 3.4)
EN

Stack Overflow用户
提问于 2018-06-14 07:04:03
回答 2查看 0关注 0票数 0

作为一名初学者,创建时间戳或格式化日期最终会比我预期的更具挑战性。有没有基本的参考例子?

EN

回答 2

Stack Overflow用户

发布于 2018-06-14 16:01:22

代码语言:txt
复制
>>> import time
>>> print(time.strftime('%a %H:%M:%S'))
Mon 06:23:14
票数 0
EN

Stack Overflow用户

发布于 2018-06-14 16:09:11

代码语言:txt
复制
import datetime

print('Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
print('Timestamp: {:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()))
print('Date now: %s' % datetime.datetime.now())
print('Date today: %s' % datetime.date.today())

today = datetime.date.today()
print("Today's date is {:%b, %d %Y}".format(today))

schedule = '{:%b, %d %Y}'.format(today) + ' - 6 PM to 10 PM Pacific'
schedule2 = '{:%B, %d %Y}'.format(today) + ' - 1 PM to 6 PM Central'
print('Maintenance: %s' % schedule)
print('Maintenance: %s' % schedule2)

输出:

Timestamp: 2014-10-18 21:31:12

Timestamp: 2014-Oct-18 21:31:12

Date now: 2014-10-18 21:31:12.318340

Date today: 2014-10-18

Today's date is Oct, 18 2014

Maintenance: Oct, 18 2014 - 6 PM to 10 PM Pacific

Maintenance: October, 18 2014 - 1 PM to 6 PM Central

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档