
#define _CRT_SECURE_NO_WARNINGS
#include <sstream>
#include <chrono>
#include <time.h>
#include <iomanip>
#include <iostream>
std::stringstream Timestamp()
{
auto now = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(now);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
std::stringstream ss;
ss << std::put_time(std::localtime(&t), "%F %T.") << std::setfill('0') << std::setw(3) << ms % 1000;
return ss;
}
int main()
{
std::cout << Timestamp().str() << std::endl;
return 0;
}
출력 예시
2021-08-19 23:27:03.063
(milliseconds를 epoch 나머지로 직접 구하는 방법 말고는 없는걸까? 기본 제공되는 함수라던가)
반응형
'미분류' 카테고리의 다른 글
| Windows Hypervisor Platform (WHP) (0) | 2021.09.30 |
|---|---|
| 제목 미정, heap memory란? stackoverflow가 좋은점 (0) | 2021.08.21 |
| class member 인 unique_ptr 의 초기화 (0) | 2021.06.29 |
| 구글번역기로 변수명 지어도 괜찮을까..? (0) | 2021.06.18 |
| 안좋은 프로그래머는 코드에 대해 걱정한다. 좋은 프로그래머는 데이터 구조와 관계에 대해 걱정한다 (0) | 2021.06.04 |