Pyhon DateTime的模块如何在相关类方法中的整理

以下的文章就是对Pyhon DateTime的模块在实际应用过程中的具体介绍,本文涉及到的Pyhon DateTime相关的类方法整理,以及其相应的代码详解,希望你在看完我们的文章会有所收获。

 

相关联的模块还有time与calendar 其中的time我们上面已经做了整理。呆会再整理下日历相比time模块来讲的话这个模块在运算上更加方便一点。现在整理一下其帮助文档上面的内容出来

构造方法:

 

 
 
 
  1. datetime(year,month,day,[hour[,minute[,
    second[,microsecond[,tzinfo]]]]]) 

 

参数说明:

 

 
 
 
  1. <!--[if !supportLists]-->· <!--[endif]-->MINYEAR
     
    <= year <= MAXYEAR   
  2. <!--[if !supportLists]-->· <!--[endif]--><= month
     
    <= 12   
  3. <!--[if !supportLists]-->· <!--[endif]--><= day
     
    <= number of days in the given month and year   
  4. <!--[if !supportLists]-->· <!--[endif]-->
    <= hour < 24   
  5. <!--[if !supportLists]-->· <!--[endif]-->0
     
    <= minute < 60   
  6. <!--[if !supportLists]-->· <!--[endif]-->
    <= second < 60   
  7. <!--[if !supportLists]-->· <!--[endif]-->
    <= microsecond < 1000000   

 

Pyhon DateTime相关类方法整理

1、today() 返回当前的本地时间值

 

 
 
 
  1. if __name__ == '__main__':  
  2. datetimedatetimes = datetime.datetime(2001,12,2)  
  3.  

 

构造方法参数要指明正确哦

 

 
 
 
  1. print datetimes.today() 

 

返回:

 
 
 
  1. 2010-03-04 14:40:51.783000  

即为当前的时间值了

2、

 
 
 
  1. now([tz]) 

 

示例:

 

 
 
 
  1. if __name__ == '__main__':  
  2. datetimedatetimes = datetime.datetime(2001,12,2)  
  3. print datetimes.now()  

 

输出:

 
 
 
  1. 2010-03-04 14:43:09.127000 

 

如果没指定参数即表示当前的时间值!以上的文章就是对Pyhon DateTime的相关实际应用方案的部分介绍。

【编辑推荐】

  1. Python环境的实际应用方案介绍与代码详解
  2. 用python pylint检查相关东西的操作方案详解
  3. Python数据结构创建的具体应用方案详解
  4. Python语法的基本概念的阐述
  5. Python编程语言的实现内幕的相关介绍
THE END