Get the time zone code

Source: Internet
Author: User
Tags time zones

Sometimes you need to get to the current time zone in the project

Ten  - :notoginseng: + 0800

+800 means the current time zone is the East eight zone.

My idea is: Pick a point in time, which is 0 points in Greenwich, then the current number of hours in a global location is the number of time zones for that location. If the current time is greater than 12 points, it proves that the location is west of Greenwich.

The code is as follows:
#include <time.h>#include<stdio.h>#include<sys/time.h>intTime_zone () {time_t currtime=1420070400; structtm* PTM = localtime (&currtime); intCHR = ptm->Tm_hour; if(Chr > A) CHR-= - ; returnCHR;}intMainintargcChar*argv[]) {printf ("Time Zone is%d\n", Time_zone ()); return 0;}

In the native execution result:

Time Zone is 8

Korean Machine execution Results:

Time Zone is 9

Get the time zone code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.