zoukankan      html  css  js  c++  java
  • 收藏:VC++获得当前系统时间的几种方案

    //方案— 优点:仅使用C标准库;缺点:只能精确到秒级

    #include <time.h>

    #include <stdio.h>

    int main( void )

    {

        time_t t = time( 0 );

        char tmp[64];

        strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",

    localtime(&t) );

        puts( tmp ); 

        return 0;

    }

    //方案二 优点:能精确到毫秒级;缺点:使用了windows API

    #include <windows.h>

    #include <stdio.h>

    int main( void )

    {

            SYSTEMTIME sys;

            GetLocalTime( &sys );

            printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n"

                    ,sys.wYear,sys.wMonth,sys.wDay

                    ,sys.wHour,sys.wMinute,sys.wSecond,sys.wMilliseconds

                    ,sys.wDayOfWeek); 

            return 0;

    }

    //方案三,优点:利用系统函数

    #include<stdlib.h>

    #include<iostream>

    using namespace std;

    void main(){

        system("time");

    }

    可以改变电脑的时间设定

    方案4:

    #include<iostream>

    #include<ctime>

    using namespace std;

    int main()

    {

    time_t now_time;

    now_time = time(NULL);

    cout<<now_time;

    return 0;

    }

    另一:_strdate(tempstr);

    另二:

    CString CTestView::GetTime()

    {

       CTime CurrentTime=CTime::GetCurrentTime();

       CString strTime;   

       strTime.Format("%d:%d:%d",CurrentTime.GetHour(),  CurrentTime.GetMinute(),CurrentTime.GetSecond());

       return strTime;

    } language=VBScript>call ReplaceSubjectHTML_emote(592915)

  • 相关阅读:
    go语言】Goroutines 并发模式
    Mysql Innodb 引擎优化 参数(innodb_buffer_pool_size)
    多key业务,数据库水平切分架构一次搞定
    Goroutine是如何工作的?
    PHP进程之信号捕捉中的declare(ticks=1)
    php多进程总结
    mysql强制性操作
    rabbitMQ高可用
    服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
    mysql在innodb索引下b+树的高度问题。
  • 原文地址:https://www.cnblogs.com/flyingfish/p/711551.html
Copyright © 2011-2022 走看看