⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datetime.cpp

📁 一套linux下的C++开发库
💻 CPP
字号:
/***************************************************************************                          datetime.cpp  -  description                             -------------------    begin                : Fri Jul 20 2001    copyright            : (C) 2001 by Mark    email                : alben@yeah.net ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include <stdio.h>#include "datetime.h"CDateTime::CDateTime(){	m_tTime = time(NULL);	localtime_r(&m_tTime, &m_stTime);}CDateTime::CDateTime(time_t tTime){	m_tTime = tTime;	localtime_r(&m_tTime, &m_stTime);}CDateTime::CDateTime(const struct tm& stTime){	m_stTime = stTime;	m_tTime = mktime(&m_stTime);}CDateTime::CDateTime(int iYear, int iMonth, int iDay, int iHour = 0, int iMinute = 0, int iSecond = 0){	m_stTime.tm_year = iYear - 1900;	m_stTime.tm_mon = iMonth - 1;	m_stTime.tm_mday = iDay;	m_stTime.tm_hour = iHour;	m_stTime.tm_min = iMinute;	m_stTime.tm_sec = iSecond;		m_tTime = mktime(&m_stTime);}string CDateTime::ShortDateTime(){	char sDateTime[15];	sprintf(sDateTime, "%04d%02d%02d%02d%02d%02d", Year(), Month(), Day(), Hour(), Minute(), Second());	return string(sDateTime);}string CDateTime::LongDateTime(char chSep1, char chSep2){	char sDateTime[20];	sprintf(sDateTime, "%04d%c%02d%c%02d %02d%c%02d%c%02d", Year(), chSep1, Month(), chSep1, Day(),					Hour(), chSep2, Minute(), chSep2, Second());	return string(sDateTime);}string CDateTime::ShortDate(){	char sDate[9];	sprintf(sDate, "%04d%02d%02d", Year(), Month(), Day());	return string(sDate);}string CDateTime::LongDate(char chSep = '-'){	char sDate[11];	sprintf(sDate, "%04d%c%02d%c%02d", Year(), chSep, Month(), chSep, Day());	return string(sDate);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -