简体   繁体   English

星期几和星期几的缩写

[英]Abbreviations for month and day of the week

I am trying to write regex to capture the output of 我正在尝试编写正则表达式来捕获输出

datetime.datetime.now().ctime()

Mon May 25 20:20:41 2015

I was wondering what are the possible outputs for the abbreviations of day of the week and month? 我想知道星期几和月几的缩写可能有什么输出?

Here's some information about the formats of the string ctime produces. 以下是有关ctime产生的字符串格式的一些信息 Basically it's always a fixed length string with that basic format. 基本上,它始终是具有该基本格式的固定长度的字符串。

Python datetime class does not invoke C ctime() function ie, it works the same even on platforms that do not provide C ctime() ( the equivalent of asctime(localtime(clock)) ). Python datetime类不会调用C ctime()函数,即,即使在不提供C ctime()相当于asctime(localtime(clock)) ),它的工作原理也相同。

CPython source code says that the format is: CPython源代码说该格式为:

static PyObject *
format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds)
{
    static const char *DayNames[] = {
        "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
    };
    static const char *MonthNames[] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };

    int wday = weekday(GET_YEAR(date), GET_MONTH(date), GET_DAY(date));

    return PyUnicode_FromFormat("%s %s %2d %02d:%02d:%02d %04d",
                                DayNames[wday], MonthNames[GET_MONTH(date)-1],
                                GET_DAY(date), hours, minutes, seconds,
                                GET_YEAR(date));
}

You could parse it using datetime.strptime(input_ctime_string, "%a %b %d %H:%M:%S %Y") in C locale. 您可以在C语言环境中使用datetime.strptime(input_ctime_string, "%a %b %d %H:%M:%S %Y")进行解析。

The above is (almost) the same as the corresponding asctime() definition : 上面的(几乎)与相应的asctime()定义相同

char *asctime(const struct tm *timeptr)
{
    static char wday_name[7][3] = {
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    };
    static char mon_name[12][3] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };
    static char result[26];


    sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
        wday_name[timeptr->tm_wday],
        mon_name[timeptr->tm_mon],
        timeptr->tm_mday, timeptr->tm_hour,
        timeptr->tm_min, timeptr->tm_sec,
        1900 + timeptr->tm_year);
    return result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM