`get date time` C++ Examples

25 C++ code examples are found related to "get date time". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: HttpHelpers.cpp    From sultan with GNU General Public License v3.0 6 votes vote down vote up
QByteArray getHttpDate(const QDateTime& dateTime /*= QDateTime::currentDateTime()*/)
			{
				static const char* dayNames[] = {NULL, "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
				static const char* monthNames[] = {NULL, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
				static const char* intNames[] = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60"};

				QDateTime utcDateTime = dateTime.toUTC();
				const QDate& date = utcDateTime.date();
				const QTime& time = utcDateTime.time();

				QByteArray httpDate; httpDate.reserve(32);
				httpDate.append(dayNames[date.dayOfWeek()]).append(", ").append(intNames[date.day()]).append(' ').append(monthNames[date.month()]).append(' ');
				Pillow::ByteArrayHelpers::appendNumber<int, 10>(httpDate, date.year());
				httpDate.append(' ').append(intNames[time.hour()]).append(':').append(intNames[time.minute()]).append(':').append(intNames[time.second()]).append(" GMT");

				return httpDate;
			} 
Example 2
Source File: xbase.cpp    From CeleX4-OpalKelly with Apache License 2.0 6 votes vote down vote up
string XBase::getDateTimeStamp()
{
    time_t tt = time(NULL);
    tm* t = NULL;
#ifdef _WIN32
    localtime_s(t, &tt);
#else
    t = localtime(&tt);
#endif
    std::stringstream ss;
    //year
    ss << (t->tm_year+1900);
    //month
    if (t->tm_mon < 10)
        ss << "0" << t->tm_mon+1;
    else 
Example 3
Source File: serverDevice.cpp    From v4l2onvif with GNU General Public License v3.0 6 votes vote down vote up
int DeviceBindingService::GetSystemDateAndTime(_tds__GetSystemDateAndTime *tds__GetSystemDateAndTime, _tds__GetSystemDateAndTimeResponse *tds__GetSystemDateAndTimeResponse) 
{
	std::cout << __FUNCTION__ << std::endl;
	ServiceContext* ctx = (ServiceContext*)this->soap->user;
	const time_t timestamp = time(NULL);
	struct tm * tm = gmtime(&timestamp);
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime = soap_new_tt__SystemDateTime(this->soap);
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->DateTimeType = tt__SetDateTimeType__Manual;
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->DaylightSavings = ctx->m_isdst;
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->TimeZone = soap_new_tt__TimeZone(this->soap);
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->TimeZone->TZ = ctx->m_timezone;
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->UTCDateTime = soap_new_tt__DateTime(this->soap);
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->UTCDateTime->Time = soap_new_req_tt__Time(this->soap, tm->tm_hour, tm->tm_min  , tm->tm_sec );
	tds__GetSystemDateAndTimeResponse->SystemDateAndTime->UTCDateTime->Date = soap_new_req_tt__Date(this->soap, tm->tm_year, tm->tm_mon+1, tm->tm_mday);
	
	return SOAP_OK;
} 
Example 4
Source File: Timer.cpp    From fonline with MIT License 6 votes vote down vote up
void Timer::GetCurrentDateTime(DateTimeStamp& dt)
{
#ifdef FO_WINDOWS
    SYSTEMTIME st;
    GetLocalTime(&st);
    dt.Year = st.wYear, dt.Month = st.wMonth, dt.DayOfWeek = st.wDayOfWeek, dt.Day = st.wDay, dt.Hour = st.wHour,
    dt.Minute = st.wMinute, dt.Second = st.wSecond, dt.Milliseconds = st.wMilliseconds;
#else
    time_t long_time;
    time(&long_time);
    struct tm* lt = localtime(&long_time);
    dt.Year = lt->tm_year + 1900, dt.Month = lt->tm_mon + 1, dt.DayOfWeek = lt->tm_wday, dt.Day = lt->tm_mday,
    dt.Hour = lt->tm_hour, dt.Minute = lt->tm_min, dt.Second = lt->tm_sec;
    struct timeval tv;
    gettimeofday(&tv, nullptr);
    dt.Milliseconds = tv.tv_usec / 1000;
#endif
} 
Example 5
Source File: Functions.cpp    From DualSPHysics with GNU Lesser General Public License v2.1 6 votes vote down vote up
std::string GetDateTimeFormatUTC(const char* format,int day,int month,int year,int hour,int min,int sec){
  time_t rawtime;
  struct tm *timeinfo;
  time(&rawtime);
  timeinfo=gmtime(&rawtime);
  timeinfo->tm_year=year-1900;
  timeinfo->tm_mon=month - 1;
  timeinfo->tm_mday=day;
  timeinfo->tm_hour=hour;
  timeinfo->tm_min=min;
  timeinfo->tm_sec=sec;
  mktime(timeinfo);
  char bufftime[256];
  strftime(bufftime,256,format,timeinfo);
  return(bufftime);
} 
Example 6
Source File: ServiceDevice.cpp    From onvif_srvd with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
int DeviceBindingService::GetSystemDateAndTime(_tds__GetSystemDateAndTime *tds__GetSystemDateAndTime, _tds__GetSystemDateAndTimeResponse &tds__GetSystemDateAndTimeResponse)
{
    DEBUG_MSG("Device: %s\n", __FUNCTION__);


    const time_t  timestamp = time(NULL);
    struct tm    *tm        = gmtime(&timestamp);

    tds__GetSystemDateAndTimeResponse.SystemDateAndTime                    = soap_new_tt__SystemDateTime(this->soap);
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->DateTimeType      = tt__SetDateTimeType__Manual;
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->DaylightSavings   = tm->tm_isdst;
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->TimeZone          = soap_new_tt__TimeZone(this->soap);
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->TimeZone->TZ      = tm->tm_zone;
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->UTCDateTime       = soap_new_tt__DateTime(this->soap);
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->UTCDateTime->Time = soap_new_req_tt__Time(this->soap, tm->tm_hour, tm->tm_min  , tm->tm_sec );
    tds__GetSystemDateAndTimeResponse.SystemDateAndTime->UTCDateTime->Date = soap_new_req_tt__Date(this->soap, tm->tm_year, tm->tm_mon+1, tm->tm_mday);

    return SOAP_OK;
} 
Example 7
Source File: SkTime.cpp    From ZUI with MIT License 6 votes vote down vote up
void SkTime::GetDateTime(DateTime* dt) {
    if (dt) {
        time_t m_time;
        time(&m_time);
        struct tm tstruct;
        gmtime_r(&m_time, &tstruct);
        dt->fTimeZoneMinutes = 0;
        dt->fYear       = tstruct.tm_year + 1900;
        dt->fMonth      = SkToU8(tstruct.tm_mon + 1);
        dt->fDayOfWeek  = SkToU8(tstruct.tm_wday);
        dt->fDay        = SkToU8(tstruct.tm_mday);
        dt->fHour       = SkToU8(tstruct.tm_hour);
        dt->fMinute     = SkToU8(tstruct.tm_min);
        dt->fSecond     = SkToU8(tstruct.tm_sec);
    }
} 
Example 8
Source File: utilities.cpp    From OpenREALM with GNU General Public License v3.0 5 votes vote down vote up
std::string io::getDateTime()
{
  time_t     now = time(nullptr);
  tm  tstruct = *localtime(&now);
  char tim[20];
  strftime(tim, sizeof(tim), "%y-%m-%d_%H-%M-%S", &tstruct);
  return std::string(tim);
} 
Example 9
Source File: CSUserMgr_Notice.cpp    From BattleServer with The Unlicense 5 votes vote down vote up
UINT64 CCSUserMgr::GetCDKeySurplusSec(INT64 &dateTime, UINT64 expire_time)
	{
		INT64 temp_time = expire_time - GetCurDateTime();
		INT64 temp_n64 = 0;

		dateTime += temp_time * 3600;
		temp_n64 = temp_time / 100;

		if (temp_n64 != 0)
		{
			dateTime += temp_time * 3600 * 24;
		}

		return eNormal;
	} 
Example 10
Source File: Timer.cpp    From eomaia with MIT License 5 votes vote down vote up
string Timer::getNowTimeDate()
{
    time_t timep;
    struct tm *p;
    time(&timep);
    p = localtime(&timep);
    stringstream stream;
    stream<<(1900+p->tm_year)<<" "<<(1+p->tm_mon)<<"/"<<p->tm_mday<<" "<<p->tm_hour<<":"<<p->tm_min<<":"<<p->tm_sec<<endl;
    return stream.str();
} 
Example 11
Source File: replay_controller.cpp    From LazzyQuant with GNU General Public License v3.0 5 votes vote down vote up
QDateTime getReplayDateTime(const QCommandLineParser &parser, const QString &option)
{
    QDateTime dateTime;
    if (parser.isSet(option)) {
        QString replayStartDateTime = parser.value(option);
        dateTime = QDateTime::fromString(replayStartDateTime, "yyyyMMddHHmmss");
        dateTime.setTimeZone(QTimeZone::utc());
    }
    return dateTime;
} 
Example 12
Source File: util.cpp    From JKSV with GNU General Public License v3.0 5 votes vote down vote up
std::string util::getDateTime(int fmt)
{
    char ret[128];

    time_t raw;
    time(&raw);
    tm *Time = localtime(&raw);

    switch(fmt)
    {
        case DATE_FMT_YMD:
            sprintf(ret, "%04d.%02d.%02d @ %02d.%02d.%02d", Time->tm_year + 1900, Time->tm_mon + 1, Time->tm_mday, Time->tm_hour, Time->tm_min, Time->tm_sec);
            break;

        case DATE_FMT_YDM:
            sprintf(ret, "%04d.%02d.%02d @ %02d.%02d.%02d", Time->tm_year + 1900, Time->tm_mday, Time->tm_mon + 1, Time->tm_hour, Time->tm_min, Time->tm_sec);
            break;

        case DATE_FMT_HOYSTE:
            sprintf(ret, "%02d.%02d.%04d", Time->tm_mday, Time->tm_mon + 1, Time->tm_year + 1900);
            break;

        case DATE_FMT_JHK:
            sprintf(ret, "%04d%02d%02d_%02d%02d", Time->tm_year + 1900, Time->tm_mon + 1, Time->tm_mday, Time->tm_hour, Time->tm_min);
            break;

        case DATE_FMT_ASC:
            strcpy(ret, asctime(Time));
            replaceCharCStr(ret, ':', '_');
            replaceCharCStr(ret, '\n', 0x00);
            break;
    }

    return std::string(ret);
} 
Example 13
Source File: modelnachgaerverlauf.cpp    From kleiner-brauhelfer-2 with GNU General Public License v3.0 5 votes vote down vote up
QDateTime ModelNachgaerverlauf::getLastDateTime(const QVariant &sudId) const
{
    QDateTime lastDt;
    for (int r = 0; r < rowCount(); ++r)
    {
        if (data(r, ColSudID) == sudId)
        {
            QDateTime dt = data(r, ColZeitstempel).toDateTime();
            if (!lastDt.isValid() || dt > lastDt)
                lastDt = dt;
        }
    }
    return lastDt;
} 
Example 14
Source File: misc.cpp    From extDB2 with GNU General Public License v3.0 5 votes vote down vote up
void MISC::getDateTime(const std::string &input_str, std::string &result)
{
	int time_offset = 0;
	if (!(input_str.empty()))
	{
		if (!(Poco::NumberParser::tryParse(input_str, time_offset)))
		{
			time_offset = 0;
		}
	}

	Poco::DateTime newtime = Poco::DateTime() + Poco::Timespan(time_offset * Poco::Timespan::HOURS);
	result = "[1,[" + Poco::DateTimeFormatter::format(newtime, "%Y,%n,%d,%H,%M") + "]]";
} 
Example 15
Source File: Timer.cpp    From FirewallEventMonitor with MIT License 5 votes vote down vote up
void Timer::GetDateAndTime(
        const LARGE_INTEGER timeStamp,
        _Out_ std::wstring* date,
        _Out_ std::wstring* time)
    {
        FILETIME fileTime;
        memcpy_s(&fileTime, sizeof(fileTime), &timeStamp, sizeof(timeStamp));
        SYSTEMTIME systemTime;
        FileTimeToSystemTime(&fileTime, &systemTime);
        GetDateAndTime(systemTime, date, time);
    } 
Example 16
Source File: Timer.cpp    From FirewallEventMonitor with MIT License 5 votes vote down vote up
void Timer::GetDateAndTime(
        const SYSTEMTIME systemTime,
        _Out_ std::wstring* date,
        _Out_ std::wstring* time)
    {
        // Date and Time formats are ISO 8601
        WCHAR timeString[128] = { 0 }, dateString[128] = { 0 };
        GetDateFormatEx(LOCALE_NAME_INVARIANT, 0, &systemTime, L"yyyyMMdd", dateString, ARRAYSIZE(dateString) - 1, nullptr);
        GetTimeFormatEx(LOCALE_NAME_INVARIANT, 0, &systemTime, L"HHmmss", timeString, ARRAYSIZE(timeString) - 1);

        date->assign(dateString);
        time->assign(timeString);
    } 
Example 17
Source File: logging.cpp    From bluepill with GNU Lesser General Public License v3.0 5 votes vote down vote up
std::string getCurDateAndTime() {
	time_t rawtime;
	struct tm * timeinfo;
	char buffer[80];
	time(&rawtime);
	timeinfo = localtime(&rawtime);
	strftime(buffer, 80, "%Y_%m_%d_%I_%M_%S", timeinfo);
	return string(buffer);
} 
Example 18
Source File: metaOutput.cxx    From HopeFOAM with GNU General Public License v3.0 5 votes vote down vote up
static METAIO_STL::string GetCurrentDateTime(const char* format)
{
  char buf[1024];
  time_t t;
  time(&t);
  strftime(buf, sizeof(buf), format, localtime(&t));
  return METAIO_STL::string(buf);
} 
Example 19
Source File: GetSpecTime.cpp    From BlackMoonKernelStaticLib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
double GetSpecDateTime(INT nYear, INT nMonth, INT nDay, INT nHour,INT nMinute,INT nSecond)
{
	
	double nSecCount = nHour * 3600;//������
	nSecCount+=(nMinute*60);
	nSecCount+=nSecond;
	double dTime = nSecCount/86400;
	double dDate = 0;
	INT nStep;

	
	if(nYear==1899)
	{
		if(nMonth==12)
		{
			if(nDay >= 30)
			{
				dDate = nDay - 30;
				return (dDate + dTime); 
			}

		}

		nStep = -1;
	}
	else if 
Example 20
Source File: Functions.cpp    From DualSPHysics with GNU Lesser General Public License v2.1 5 votes vote down vote up
std::string GetDateTimeFormat(const char* format,int nseg){
  time_t rawtime;
  struct tm *timeinfo;
  time(&rawtime);
  rawtime+=nseg;
  timeinfo=localtime(&rawtime);
  //timeinfo=gmtime(&rawtime);
  char bufftime[256];
  strftime(bufftime,256,format,timeinfo);
  return(bufftime);
} 
Example 21
Source File: NationalTime.cpp    From wubiuefi with GNU General Public License v2.0 5 votes vote down vote up
bool MyGetDateFormat(LCID locale, DWORD flags, CONST SYSTEMTIME *time, 
    LPCTSTR format, CSysString &resultString)
{
  resultString.Empty();
  int numChars = ::GetDateFormat(locale, flags, time, format, NULL, 0);
  if(numChars == 0)
    return false;
  numChars = ::GetDateFormat(locale, flags, time, format,
      resultString.GetBuffer(numChars), numChars + 1);
  resultString.ReleaseBuffer();
  return (numChars != 0);
} 
Example 22
Source File: string_tools.cpp    From SCONE with GNU General Public License v3.0 5 votes vote down vote up
std::string GetDateTimeExactAsString()
	{
		// #todo: depeicate
		// users that run multiple simulations in quick succession
		// should differentiate them through the .R 'random_seed' tag
		std::time_t today = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
		auto tm = std::localtime( &today );
		auto p = std::chrono::high_resolution_clock::now();
		auto nsec = std::chrono::duration_cast<std::chrono::nanoseconds>( p.time_since_epoch() );
		auto frac_secs = nsec.count() % 1000000;
		return stringf( "%02d%02d.%02d%02d%02d.%06d", tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, frac_secs );
	} 
Example 23
Source File: platform.c    From awtk with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ret_t date_time_get_now_impl(date_time_t* dt) {
  SYSTEMTIME wtm;
  GetLocalTime(&wtm);

  dt->second = wtm.wSecond;
  dt->minute = wtm.wMinute;
  dt->hour = wtm.wHour;
  dt->day = wtm.wDay;
  dt->wday = wtm.wDayOfWeek;
  dt->month = wtm.wMonth;
  dt->year = wtm.wYear;

  return RET_OK;
} 
Example 24
Source File: mlibtime.cpp    From lambdatwist-p3p with GNU General Public License v3.0 4 votes vote down vote up
std::string getIsoDateTime()
{

    std::stringstream now;

    auto tp = std::chrono::system_clock::now();
    auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( tp.time_since_epoch() );
    size_t modulo = ms.count() % 1000;

    time_t seconds = std::chrono::duration_cast<std::chrono::seconds>( ms ).count();

#ifdef _MSC_VER

    struct tm T;
    localtime_s(&T, &seconds);
   // now << std::put_time(&T, "%Y-%m-%d %H-%M-%S.");

#else

#define HAS_STD_PUT_TIME 1
#if HAS_STD_PUT_TIME
//    now << std::put_time( localtime( &seconds ), "%Y-%m-%d %H-%M-%S." );
#else
//# warning "deprecated fallback for std::put_time!"
    char buffer[25]; // holds "2013-12-01 21:31:42"

    // note: localtime() is not threadsafe, lock with a mutex if necessary
    if( strftime( buffer, 25, "%Y-%m-%d %H-%M-%S.", localtime( &seconds ) ) ) {
        now << buffer;
    }

#endif // HAS_STD_PUT_TIME

#endif //_MSC_VER

    // ms
    now.fill( '0' );
    now.width( 3 );
    now << modulo;

    return now.str();
} 
Example 25
Source File: CSUserMgr_Notice.cpp    From BattleServer with The Unlicense 4 votes vote down vote up
UINT64 CCSUserMgr::GetCurDateTime()
{
	time_t curtime=time(0); 
	tm tim =*localtime(&curtime); 
	int day,mon,year,hour,min,sec; 
	day=tim.tm_mday;
	mon=tim.tm_mon;
	year=tim.tm_year;
	hour=tim.tm_hour;
	min = tim.tm_min;
	sec = tim.tm_sec;
	year += 1900;
	mon += 1;

	stringstream t_ss;
	t_ss<<year;
	//�¡��ա�ʱ���֡��벻����λ�IJ�0
	if (mon < 10){
		t_ss<<0;
	}
	t_ss<<mon;
	if (day < 10){
		t_ss<<0;
	}
	t_ss<<day;
	if (hour<10){
		t_ss<<0;
	}
	t_ss<<hour;

	//תstring
	string t_sec;
	t_ss>>t_sec;

	//תUint64
	stringstream ss;
	ss<<t_sec;

	UINT64 un64_t;
	ss>>un64_t;

	return un64_t;
}