zoukankan      html  css  js  c++  java
  • python bug the C library strftime function.

    import time
    def date2mktime(date, format_='%Y-%m-%d'):
    return int(time.mktime(time.strptime(date, format_)))
    d=date2mktime('4000-01-01')
    print(d)


    C:UsersPublicpy36python.exe D:/bizPythonDouban/selfPlatformAskAnswerProjeect/b.py
    Traceback (most recent call last):
      File "D:/bizPythonDouban/selfPlatformAskAnswerProjeect/b.py", line 4, in <module>
        d=date2mktime('4000-01-01')
      File "D:/bizPythonDouban/selfPlatformAskAnswerProjeect/b.py", line 3, in date2mktime
        return int(time.mktime(time.strptime(date, format_)))
    OverflowError: mktime argument out of range
    

      



    C:Userssas.PyCharm2017.2systempython_stubs-1603771140 ime.py


    def strptime(string, format): # real signature unknown; restored from __doc__
    """
    strptime(string, format) -> struct_time

    Parse a string to a time tuple according to a format specification.
    See the library reference manual for formatting codes (same as
    strftime()).

    Commonly used format codes:

    %Y Year with century as a decimal number.
    %m Month as a decimal number [01,12].
    %d Day of the month as a decimal number [01,31].
    %H Hour (24-hour clock) as a decimal number [00,23].
    %M Minute as a decimal number [00,59].
    %S Second as a decimal number [00,61].
    %z Time zone offset from UTC.
    %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.
    %I Hour (12-hour clock) as a decimal number [01,12].
    %p Locale's equivalent of either AM or PM.

    Other codes may be available on your platform. See documentation for
    the C library strftime function.
    """
    return struct_time



    C library function - strftime() http://www.tutorialspoint.com/c_standard_library/c_function_strftime.htm


    #include <stdio.h>
    #include <time.h>
    
    int main () {
       time_t rawtime;
       struct tm *info;
       char buffer[80];
    
       time( &rawtime );
    
       info = localtime( &rawtime );
    
       strftime(buffer,80,"%x - %I:%M%p", info);
       printf("Formatted date & time : |%s|
    ", buffer );
      
       return(0);
    }
    

      



  • 相关阅读:
    60款很酷的 jQuery 幻灯片演示和下载
    分享27款非常棒的 jQuery 表单插件
    10款新鲜出炉的 jQuery 插件
    5 个很炫的 HTML5 游戏
    12款高质量的免费 HTML 网页模板下载
    jquery插件整理篇(四)自动补全类插件
    jquery插件整理篇(三)图片展示插件
    超强1000个jquery插件!
    34个漂亮的应用程序后台管理系统界面(系列二)
    jquery插件整理篇(九)数据验证类
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10042655.html
Copyright © 2011-2022 走看看