`
mlzboy
  • 浏览: 701890 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

python下datetime类型的转换

阅读更多
print datetime.strptime("2010-04-01 00:04:57.277","%Y-%m-%d %H:%M:%S.%f")
参考文章:
http://docs.python.org/library/datetime.html#strftime-strptime-behavior
Directive Meaning Notes
%a Locale’s abbreviated weekday name.  
%A Locale’s full weekday name.  
%b Locale’s abbreviated month name.  
%B Locale’s full month name.  
%c Locale’s appropriate date and time representation.  
%d Day of the month as a decimal number [01,31].  
%f Microsecond as a decimal number [0,999999], zero-padded on the left (1)
%H Hour (24-hour clock) as a decimal number [00,23].  
%I Hour (12-hour clock) as a decimal number [01,12].  
%j Day of the year as a decimal number [001,366].  
%m Month as a decimal number [01,12].  
%M Minute as a decimal number [00,59].  
%p Locale’s equivalent of either AM or PM. (2)
%S Second as a decimal number [00,61]. (3)
%U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. (4)
%w Weekday as a decimal number [0(Sunday),6].  
%W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. (4)
%x Locale’s appropriate date representation.  
%X Locale’s appropriate time representation.  
%y Year without century as a decimal number [00,99].  
%Y Year with century as a decimal number.  
%z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive). (5)
%Z Time zone name (empty string if the object is naive).  
%% A literal '%' character.  


分享到:
评论
1 楼 f002489 2011-03-25  
strftime

相关推荐

    python中时间转换datetime和pd.to_datetime详析

    主要给大家介绍了关于python中时间转换datetime和pd.to_datetime的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用python具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧

    将python的datetime转换为unix时间戳code.txt

    将python的datetime转换为unix时间戳 13位时间戳获取方法 将unix时间戳转换为python的datetime

    python timestamp和datetime之间转换详解

    主要为大家详细介绍了python timestamp和datetime之间转换,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    python使用datetime模块进行时间、日期、时间戳的转换

    python使用datetime模块进行时间、日期、时间戳的转换

    python时间类型相互转换

    在利用python处理数据时,经常会出现限定格式数据无法读取问题。此代码文档明确说明时间格式数据的关系、转换。

    python utc datetime转换为时间戳的方法

    最近python代码遇到了一个神奇的需求, 就是如果将python utc datetime转换为时间戳. 百度找到都是使用time.mktime(xxx) 但是看到官网文档里写 time.mktime(t) This is the inverse function of localtime() 而且亲...

    时间字符串转换成日期对象datetime的方法

    您可能感兴趣的文章:sql语句中如何将datetime格式的日期转换为yy-mm-dd格式将WMI中的DateTime类型转换成VBS时间的函数代码LINQ字符串向datetime 转换时失败的处理方法Sql中将datetime转换成字符串的

    python datetime时间格式的相互转换问题

    主要介绍了python datetime时间格式的相互转换问题,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

    Python Numpy库datetime类型的处理详解

    在NumPy 1.7版本开始,它的核心数组(ndarray)对象支持datetime相关功能,由于’datetime’这个数据类型名称已经在Python自带的datetime模块中使用了, NumPy中时间数据的类型称为’datetime64’。 单个时间格式...

    Python利用datetime计算时间差

    Python使用datetime模块生成计算时间差函数 import datetime def difftime(off_bt, on_bt): #输入的日期和时间是字符串形式,需要先将字符串格式化为datetime形式。 time1 = datetime.datetime.strptime(off_bt, %...

    图解Python时间和日期time和datetime数据类型转换

    文章目录前言4大数据类型图解time.struct_timetime.struct_time ⇌ strtime.struct_time ⇌ ...主要内容:时间数据类型转换 4大数据类型 import time, datetime _print = lambda x: print('\033[033m%s\033[0m' % type

    Python时间和字符串转换操作实例分析

    主要介绍了Python时间和字符串转换操作,结合实例形式分析了Python时间的格式化输出、时间戳转换、datetime转换字符串等相关操作技巧,需要的朋友可以参考下

    对python xlrd读取datetime类型数据的方法详解

    使用xlrd读取出来的时间字段是类似41410.5083333的浮点数,在使用时需要转换成对应的datetime类型,下面代码是转换的方法: 首先需要引入xldate_as_tuple函数 from xlrd import xldate_as_tuple 使用方法如下: #d...

    Python中时间datetime的处理与转换用法总结

    python中日期类datetime功能比较强大,使用起来很方便,把常用的两种用法总结如下: from datetime import datetime from datetime import timedelta # 日期格式转换为字符串 NOW = datetime.now() TODAY = NOW....

    Python时间格式转换

    一、标准库 1、import time ...datatime模块重新封装了time模块,提供更多接口,提供的类有:date,time,datetime,timedelta,tzinfo。 二、格式名称 时间格式名称:时间戳 示例:1584039884.0 float格式

    sql语句中如何将datetime格式的日期转换为yy-mm-dd格式

    您可能感兴趣的文章:将WMI中的DateTime类型转换成VBS时间的函数代码LINQ字符串向datetime 转换时失败的处理方法时间字符串转换成日期对象datetime的方法Sql中将datetime转换成字符串的方法(CONVERT)Python中实现对...

Global site tag (gtag.js) - Google Analytics