首页 > 编程语言 > 详细

linux c++获取年月日

时间:2021-02-13 08:33:53      阅读:111      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <string.h> 
#include <string>
#include <iostream>
using namespace std;
#define CHAR char
int GetDate(const string &fmt, string &result)
{
	CHAR buf[256];
	time_t 	currtime;
	time(&currtime);
	struct tm *today = localtime(&currtime);
	if(strftime(buf, 256, fmt.c_str(), today)>0)
	{
		result = string(buf);
		return result.size();
	}
	return -1;
}

 
int main()
{
   string Val;
   GetDate("%Y-%m-%d",Val);;
   cout<<Val<<endl;
   return 0;
}

 

linux c++获取年月日

原文:https://www.cnblogs.com/hshy/p/14399751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!