这是一个小的Python包,它使用字母符号将标准时间戳编码为缩写形式。

alphabetic-timestamp的Python项目详细描述


字母时间戳

PyPI-StatusPyPI-VersionsGitHub issuesBuild StatusPyPI - StatusGitHub license

这是一个小Python包,它使用字母符号将标准时间戳编码为短格式。在

安装

pipinstallalphabetic-timestamp

说明

用户可以使用两个基进行编码。它用另外两个不同的符号列表来编码。在

  • 基准36

  • 基准62

编码示例

此示例显示日期时间2020-01-01 20:20:20.002000的编码。意思是时间戳1577906420.002。在

Time UnitsBase36Base62
secondsq3g0dw1IMJxy
deciseconds78yg3uwhdRlpu
centiseconds20hkh2kw2MeBs6Q
millisecondsk4voqpsyrMm2x6q

基数36的符号

^{pr2}$

基数62的符号

importalphabetic_timestampasatsprint(ats.base62.symbols)>>>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

接口

这个例子显示了base36的接口。base62的接口相同。在

importdatetimeimportalphabetic_timestampasatsdt=datetime.datetime.now()ts=dt.timestamp()ats.base36.now(time_unit=ats.TimeUnit.seconds)ats.base36.from_datetime(dt,time_unit=ats.TimeUnit.seconds)ats.base36.from_timestamp(ts,time_unit=ats.TimeUnit.seconds)ats.base36.to_datetime("q67vhw",time_unit=ats.TimeUnit.seconds,time_zone=None)ats.base36.to_timestamp("q67vhw",time_unit=ats.TimeUnit.seconds)

注意:字符串“q67vhw”是编码时间戳的唯一示例。在

示例

此软件包与Python2.7和Python3.4+兼容。但是这些例子是用Python3.6编写的。在

编码和打印

importalphabetic_timestampasatsprint(ats.base36.now())# Current DT: 2020-02-24 18:34:44.349162>>>q67vhw

编码和解码

importdatetimeimportalphabetic_timestampasats# DATETIME -> ALPHABETIC_TIMESTAMP -> DATETIMEdt=datetime.datetime.now()alphabetic_ts_36=ats.base36.from_datetime(dt)decoded_ts_36=ats.base36.to_datetime(alphabetic_ts_36)alphabetic_ts_62=ats.base62.from_datetime(dt)decoded_ts_62=ats.base62.to_datetime(alphabetic_ts_62)# TIMESTAMP -> ALPHABETIC_TIMESTAMP -> TIMESTAMP ts=dt.timestamp()alphabetic_ts_36=ats.base36.from_timestamp(ts)decoded_ts_36=ats.base36.to_timestamp(alphabetic_ts_36)alphabetic_ts_62=ats.base62.from_timestamp(ts)decoded_ts_62=ats.base62.to_timestamp(alphabetic_ts_62)

时间单位

importdatetimeimportalphabetic_timestampasatsdt=datetime.datetime.now()# Set time unit for current timestampnow36_ts=ats.base36.now()# default: ats.TimeUnit.secondsnow36_ts=ats.base36.now(time_unit=ats.TimeUnit.seconds)# Set time unit for specific datetime and timestampalphabetic_ts_36=ats.base36.from_datetime(dt,time_unit=ats.TimeUnit.seconds)alphabetic_ts_36=ats.base36.from_timestamp(dt.timestamp(),time_unit=ats.TimeUnit.seconds)# Examples of available time unitsnow36_ts=ats.base36.now(time_unit=ats.TimeUnit.seconds)now36_ts=ats.base36.now(time_unit=ats.TimeUnit.deciseconds)now36_ts=ats.base36.now(time_unit=ats.TimeUnit.centiseconds)now36_ts=ats.base36.now(time_unit=ats.TimeUnit.milliseconds)

可能的问题

可能存在由bug in standard datetime module引起的问题。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java SUN次要代码309含义   java避免为空元素生成XML自关闭标记,并生成自定义的<XML>开始标记   java使用json和restful将数组数据从本地sqlite数据库插入SQL Server   java Spring Boot 1.5.9字符编码问题   LInkedIn讨论中的java 401错误   位图Java:检查多个位向量/位集是否相交的最快方法?   macos如何让Java应用程序以图标出现在Mac OS X dock中   java如何删除netbeans中的@SuppressWarnings(“未使用的”)?   apachestorm中的java自定义序列化   java可以退出代码还是应该终止main?   递归如何在Java中递归地绘制简单的线条?   unicode在Java中确定特定字体是否可以呈现特定字符   打开并阅读带有Selenium/Katalon(Java)特定标题的电子邮件文本(来自Gmail)