In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to convert UTC time to local local time, I believe that most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.
Preface
There is a difference of 8 time zones between UTC time DateTime.UtcNow and system local time DateTime.Now, and 15 time zones between American local time and Beijing time: the United States, while UTC time is generally used to unify regional time differences.
Scene
1. If there is a website for global users, the time data is generally stored in UTC format, so that the time is uniform and can be accurately converted according to the local time zone.
two。 The problem with storing local time is that if you change the time zone, the time is not displayed correctly. Therefore, when we store time, it is best to store UTC time to facilitate correct conversion.
Description
1. The standard library provides standard functions that can be converted without the help of Win32 API.
Examples
/ / test_datetime_format.cpp: defines the entry point for the console application. / / # include "stdafx.h" # include # include / / 2014-09-13T10:52:36Z//2014-09-13 10 include 52include # include # include / / 2014-09-13T10:52:36Z//2014-09-13 10V 52RV 36char * ConvertUtcToLocalTime (struct tm* t2meme Const char* date) {struct tm t; memset (& tMed 0meme sizeof (t)); t.tm_year = atoi (date)-1900; t.tm_mon = atoi (date+5)-1; t.tm_mday = atoi (date+8); t.tm_hour = atoi (date+11); t.tm_min = atoi (date+14) T.tm_sec = atoi (date+17); time_t tt = _ mkgmtime64 (& t); if (tt! =-1) {if (T2 = = NULL) {T2 = & t;} * T2 = * localtime (& tt); char* ds = (char*) malloc (24); memset (ds, 0,24) Sprintf (ds, "% .4d -% .2d -% 2d% .2d:% .2d:% .2d", T2-> tm_year + 1900, T2-> tm_mon + 1, T2-> tm_mday, T2-> tm_hour, T2-> tm_min, T2-> tm_sec); return ds;} return NULL } / / https://www.w3.org/TR/NOTE-datetime//https://msdn.microsoft.com/en-us/library/2093ets1.aspx//2014-09-13T10:52:36Zint _ tmain (int argc, _ TCHAR* argv []) {const char* kTime = "2014-09-13 18:52:36"; std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.