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 }
  • 相关阅读:
    批量删除.svn文件夹、.svn文件
    Windows 7下Git SSH 创建Key的步骤
    Git:本地项目与远程仓库的git/clone
    git解决二进制文件冲突
    git设置mergetool可视化工具
    redhat7.2配置yum源
    project2016安装与破解
    strace 使用案例
    运维老鸟教你安装centos6.5如何选择安装包
    CSS限制
  • 原文地址:https://www.cnblogs.com/savennist/p/12378160.html
Copyright © 2011-2022 走看看