zoukankan      html  css  js  c++  java
  • 时间相关

    #include<iostream>
    #include "windows.h"
    #include<string>
    #include<time.h>   
    using namespace std;

    void main()
    {

        char str[] ="13:23:56"; //时间
        const char * split = ":";//分隔符
        char * p;
        char *ps[3];
        p = strtok (str,split);
        while(p!=NULL) {
            static int i=0;
            ps[i]=p;
            //printf ("%s\n",p);
            i++;
            p = strtok(NULL,split);
        }
        for(int j=0;j<3;j++)
        {
            printf("%s\n",ps[j]);
        }

        //转换出时间
        time_t mytime;
        struct tm *now;
        time( &mytime);
        now = localtime( &mytime);
        
        now->tm_min   =atoi(ps[0]);  
        now->tm_hour   =atoi(ps[1]);  
        //now->ti_hund   =0;   //   其实我也不知道这个成员是干啥的  
        now->tm_sec   =atoi(ps[2]);    
        //settime(&mytime);   
        printf("........................\n");
        printf("%2u%2u%2u",now->tm_hour,now->tm_min,now->tm_sec+5);
        getchar();
    }






    #include<iostream>
    #include "windows.h"
    #include<string>
    #include<time.h>
    #include<atltime.h>
    using namespace std;

    void main()
    {

        ////CTime 转CString
        //CTime currTime;
        //CString str;
     //   currTime=GetCurrentTime();
        //str=currTime.Format("%H:%M:%S");
        //wcout<<str.GetString()<<endl;
        //CTimeSpan spanTime;
        //spanTime=20;
        //currTime+=spanTime;
        //str=currTime.Format("%H:%M:%S");
        //wcout<<str.GetString()<<endl;
        //getchar();

        //CString 转CTime

        CString   timestr   =   "2000年04月05日";  
      int   a,b,c   ;  
      sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d月%d日",&a,&b,&c);  
      CTime   time(0,0,0,a,b,c);     

        CString str;
        str=time.Format("%H:%M:%S");
        wcout<<str.GetString()<<endl;
        getchar();
        /*CString sss("23:13:23");
        int a,b,c;
        sscanf(sss.GetBuffer(sss.GetLength()),"%d:%d:%d",&a,&b,&c);
        CTime timess(0,0,0,a,b,c);
        str=timess.Format("%H:%M:%S");
        wcout<<str.GetString()<<endl;*/

    }                                                                                                                                                        char szFileName[256]={0};

    time_t t = time(0); 

    char szTimeNow[64]; 

    strftime( szTimeNow, sizeof(szTimeNow), "%Y%m%d%H%M%S",localtime(&t) ); 

    sprintf(szFileName,"userlabel_%s.txt",szTimeNow);

    printf("%s",szFileName);


  • 相关阅读:
    C# Mongo Client 2.4.2创建索引
    MongoDB Driver:使用正确的姿势连接复制集
    C# Mongo Client 2.4.2判断是否存在表
    c# Mongodb批量更新
    c# Mongodb创建自增列
    class A where T:new()是什么意思
    Dapper Extensions中修改Dialect
    golang 中的 sizeof 以及 golang中的 union
    将c语言的结构体定义变成对应的golang语言的结构体定义,并将golang语言结构体变量的指针传递给c语言,cast C struct to Go struct
    golang 与 c语言 之间传递指针的规则提案
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/1570139.html
Copyright © 2011-2022 走看看