zoukankan      html  css  js  c++  java
  • 【python】time,datetime,string相互转换

    python 字符串和日期之间转换 StringAndDate

    ''''' 
    Created on 2013-7-25 
      
    @author: Administrator 
    '''
    from datetime import datetime 
    class StringAndDate(object): 
        
      ''''' String to Date(datetime) or date to string '''
        
      def stringToDate(self,string): 
        #example '2013-07-22 09:44:15+00:00' 
        dt = datetime.strptime(string, "%Y-%m-%d %H:%M:%S+00:00") 
        #print dt 
        return dt 
        
      ''''' Date(datetime) to String '''
        
      def dateToString(self,date): 
        ds = date.strftime('%Y-%m-%d %H:%M:%S') 
        return ds 
        
      ''''' return n hours after datetime '''
        
      def getAfterDate(self,n): 
        dnow = datetime.datetime.now() 
        dafter = dnow + datetime.timedelta(hours=n) 
        #dafter.ctime() 
        return dafter

  • 相关阅读:
    寒假学习进度7
    寒假学习进度3
    寒假学习进度6
    寒假学习进度5
    寒假学习进度8
    加分项
    每日博客
    每日博客
    每日博客
    每日博客
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/7827563.html
Copyright © 2011-2022 走看看