본문 바로가기
C++/C++ Common

Time

by doublerabbits 2023. 3. 30.

 

#include "pch.h"
#include <iostream>
#include <string>
#include <ctime>
#include <Windows.h>

using namespace std;
using namespace System;

void ShowCurrentTime_Seconds();
void ShowCurrentTime();
void ShowElapsedTime();

int main()
{
    ShowCurrentTime_Seconds();
    ShowCurrentTime();
    ShowElapsedTime();

    std::string str;
    std::getline(std::cin, str);

    return 0;
}


void ShowCurrentTime_Seconds()
{
    cout << __FUNCTION__ << endl;
    time_t seconds;
    cout << "since 1970 : " << time(&seconds) << endl;
    cout << "seconds : " << seconds << endl;
    cout << endl;
}

void ShowCurrentTime()
{
    cout << __FUNCTION__ << endl;
    time_t tt;
    struct tm* t = new struct tm;
    time(&tt);
    localtime_s(t, &tt);
    cout << "year : " << t->tm_year << " + 1900 = " << t->tm_year + 1900 << endl;
    cout << "month : " << t->tm_mon << " + 1 = " << t->tm_mon + 1 << endl;
    cout << "day : " << t->tm_mday << endl;
    cout << "hour : " << t->tm_hour << endl;
    cout << "minute : " << t->tm_min << endl;
    cout << "second : " << t->tm_sec << endl;
    cout << endl;

    delete t;
}

void ShowElapsedTime()
{
    cout << __FUNCTION__ << endl;

    clock_t start, end;

    start = clock();
    Sleep(3000);
    end = clock();
    cout << "Elapsed time : " << (double)(end - start) << " ms" << endl;

    cout << endl;
}

 

'C++ > C++ Common' 카테고리의 다른 글

함수 결과 처리 코드 간소  (0) 2024.05.29
가변 인수 매크로  (0) 2023.03.30
Bit Shift  (0) 2023.03.27
시간 출력  (0) 2022.11.05
string formatting  (0) 2022.08.09