zoukankan      html  css  js  c++  java
  • 日期函数操作模板

     1 #include<iostream>
     2 #include<ctime>
     3 #include<cstring>
     4 using namespace std;
     5 const char weekdiary[][6]={
     6     {""},
     7     {"Mon"},
     8     {"Tue"},
     9     {"Wed"},
    10     {"Thur"},
    11     {"Fri"},
    12     {"Sat"},
    13     {"Sun"},
    14 };
    15 
    16 const char monthdiary[][6]={
    17     {""},
    18     {"Jan"},
    19     {"Feb"},
    20     {"Mar"},
    21     {"Apr"},
    22     {"May"},
    23     {"Jun"},
    24     {"Jul"},
    25     {"Aug"},
    26     {"Sept"},
    27     {"Oct"},
    28     {"Nov"},
    29     {"Dec"},
    30 };
    31 
    32 int main()
    33 {
    34    time_t now = time(0);
    35    char* t = ctime(&now);
    36    cout<<t;
    37    //
    38    char week[6];
    39    char month[6];
    40    memset(week,0,sizeof(week));
    41    memset(month,0,sizeof(month));
    42    int day,hour,minute,second,year;
    43    sscanf(t,"%s %s %d %d:%d:%d %d
    ",week,month,&day,&hour,&minute,&second,&year);
    44    //
    45    cout<<week<<endl;
    46    cout<<month<<endl;
    47    printf("---------------
    ");
    48    for(int i=1;i<8;i++)
    49    {
    50        if(!memcmp(week,weekdiary[i],sizeof(weekdiary[i])))
    51        {
    52            cout<<"weekday "<<i<<endl;
    53            break;
    54        }
    55    }
    56    for(int i=1;i<13;i++)
    57    {
    58        if(!memcmp(month,monthdiary[i],sizeof(monthdiary[i])))
    59        {
    60            cout<<"month "<<i<<endl;
    61            break;
    62        }
    63    }
    64    printf("%d
    ",day);
    65    printf("%d
    ",hour);
    66    printf("%d
    ",minute);
    67    printf("%d
    ",second);
    68    printf("%d
    ",year);
    69    return 0;
    70 }
  • 相关阅读:
    PHP7.27: connect mysql 5.7 using new mysqli
    PHP: Browser, Operating System (OS), Device, and Language Detect
    PHP 在WIN10 下配置
    MySQL chartset
    學習Echart 2.2.7
    The open source JavaScript graphing library that powers Plotly
    D3.js 制作中国地图
    FastReport.Net
    CSS 3D transforms
    SparkCore的调优之开发调优
  • 原文地址:https://www.cnblogs.com/savennist/p/12378160.html
Copyright © 2011-2022 走看看