Skip to content

Instantly share code, notes, and snippets.

@sailfish009
Created February 19, 2018 04:12
Show Gist options
  • Save sailfish009/9cffd8bc21d87819f401c07335cc5ab1 to your computer and use it in GitHub Desktop.
Save sailfish009/9cffd8bc21d87819f401c07335cc5ab1 to your computer and use it in GitHub Desktop.
unsigned int get_current_date()
{
time_t currentTime;
tm local_Time;
time(&currentTime); // Get the current time
localtime_s(&local_Time, &currentTime); // Convert the current time to the local time
int Year = local_Time.tm_year + 1900;
int Month = local_Time.tm_mon + 1;
int Day = local_Time.tm_mday;
char tmp_str[1024];
sprintf_s(tmp_str, sizeof(tmp_str), "%04d%02d%02d", Year, Month, Day);
std::string str(tmp_str);
unsigned int current_date = std::stoul(str, nullptr, 16);
printf("date: %s\n", str.c_str());
printf("date: 0x%08x\n", current_date);
return current_date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment