close

Setup system datetime by local time zone name which is encoded according to IEEE 1003.1 (POSIX) in C

prerequisiteint matchStrPosAt()char *strmhead()char *strcutail()int getTZ(char **tz)int SetTZ(char *timezone)

 

 

  1
  2
  3
  4
  5
  6
  7
  8
  9
 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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
/*
 * ctzset.c
 *
 * Created by Jackie Xie on 2011-08-20.
 * Copyright 2011 Jackie Xie. All rights reserved.
 *
 */

#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>

typedef enum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} Days;
typedef enum {First, Second, Third, Fourth, Fifth} Weeks;
typedef enum {January = 1, February, March, April, May, June, July, August, September, October, November, December} Months; 	

typedef struct {
	int hour;
	int minute;
	int second;
} Time;

typedef struct {
	Time time;
	Days day;
	Weeks week;
	Months month;
	int year;
	time_t ptime;
} datetime;

int years[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

/* ======================(function header)========================
Function Name:char* itos (){}
Description:to convert integer to string
Arguments:unsigned n
Return:a string
written by jackiexie
Date: 2007/07/10
================================================================*/
char tmpbuf[17];
char* itos (int n)
{
  int i=0,j;
  //char* s;
  //char* u;
  char s[17];
  //s= (char*) malloc(17);
  //u= (char*) malloc(17);
  
  do{
    s[i++]=(char)( n%10+48 );
    n-=n%10;
  }
  while((n/=10)>0);
  for (j=0;j<i;j++)
  tmpbuf[i-1-j]=s[j];

  tmpbuf[j]='\0';
  return tmpbuf;
}


/* ======================(function header)========================
Function Name: char *GetStrBetweenStr(char *,
 char *,char *)
Description: retrieve a string from between left position
 and right position string.
Arguments:char *s,char *lstr,char *rstr
Return: string
written by jackie xie
Date: 2007/07/10
================================================================*/
char *GetStrBetweenStr(char *s,char *lstr,char *rstr)
{
   char *p=s,*lp=s,*rp;
   do
   {
      /*trim(lstr);
 trim(rstr);*/
      lp=strstr(lp,lstr);
      if(lp)
      {
         rp=lstr;
         do lp++; while(*rp++);
         lp--;
         rp=strstr(lp,rstr);
         if(rp)
         {
            if(lp!=rp)
            {
               do *p++=*lp++; while(lp<rp);
               lp--;
            }
            rp=rstr;
            do lp++; while(*rp++);
            lp--;
         }
      }
   } while(lp);
   *p=0;
   return s;
}

/* ======================(function header)========================
Function Name: int matchStrPosAt (const char *, const char *)
Description: find the sub-string from the source string.
Arguments: const char *, const char *
Return: Returns "the array element number"(or "position") where 
 "sub-string" matches before in "original string", or return 
 "-1" if substr is not present in "original string".
written by jackie xie
Date : 2007/07/10
================================================================*/
/* 
 * delimiters <= n:return position before n-th matched substr.
 * delimiters = 0:do nothing.
 * delimiters >= n:return position after n-th matched substr.
 */
int matchStrPosAt (char * substr, char * str, int delimiters)
{
	int i = -1, k, str_index, total = 0;
	int substr_len = strlen(substr), str_len = strlen(str);
	int matchpos = -1;
	int delimiter[str_len], ind_delim = 0;
	//int n = abs(delimiters);

	for(k=0; k<=str_len ; k++)
		delimiter[k] = -1;

	if (str == NULL || substr == NULL) return -1;

	/* substr has to be smaller than str */
	if (substr_len > str_len) return -1;

	/* look through str for substr, stopping at end of string or when the length
 * of substr exceeds the remaining number of characters to be searched */ 
	while (str[++i] != '\0' && (str_len - i + 1) > substr_len) 
	{
		for (str_index = 0; str_index < substr_len; ++str_index)
		{
			/* definitely not at location i */
			if (str[i + str_index] != substr[str_index])
				break;
			/* if last letter matches, then we know the whole thing matched */
			else if (str_index == substr_len - 1)
			{
				if(delimiters >= 1)
				{
					i += substr_len -1;
					delimiter[++ind_delim] = i;
					//printf("delimiter[%d] = %d\n", ind_delim, delimiter[ind_delim]);
				}
				else if(delimiters == 0)
					return i;
				else if(delimiters == -1)
					total++;
			}
		}
	}

	if(delimiters == 0)
		return -1;						/* substr not present in str */
	else if(delimiters == -1)
		return total;					/* the total numbers of substr */
	else if(delimiters < ind_delim)
		matchpos = delimiter[delimiters];
	else
		matchpos = delimiter[ind_delim];

	return matchpos;
}

/* ======================(function header)========================
Function Name: int strcutail (char *str, const char *n, int pos)
Description: To remove the sub-string which is starting at 
 n-th delimiter(or include it) to the end of input string.
Arguments: char *, const char *
Return: Returns the string which was cut the tailed sub-string off.
written by Jackie Xie
Date : 2011/07/15
================================================================*/
char *strcutail (char *str, const char *n, int pos)
{
	int i, _newStrLen = matchStrPosAt(n, str, abs(pos));
	char* _new;
	
	if(_newStrLen > 0){
		if (pos >= 0)
			++_newStrLen;			
		if ((_new = (char *)malloc(_newStrLen)) == NULL)
			return "NULL";

		(_new)[_newStrLen] = '\0';		

		/* copy sub-string from the head of the string to the specified delimiter */
		for (i = 0; i < _newStrLen; ++i)
			(_new)[i] = str[i];

		strcpy(str, _new);
		free (_new);
	}
	return str;
}

/* ======================(function header)========================
Function Name: int strmhead (char *str, const char *n, int pos)
Description: To cut the front of sub-string which is starting at the
 matched delimiter and ending of the input string.
Arguments: char *, const char *
Return: The string which was cut the front of input string till the 
 specified delimiter.
written by Jackie Xie
Date : 2011/08/12
================================================================*/
char *strmhead (char *str, const char *n, int pos)
{
	int i, _matchedStrLen = matchStrPosAt(n, str, abs(pos));
	int str_len = strlen(str);
	int _newStrLen = 0;
	
	char* _new;
	
	if(_matchedStrLen > 0){
		if (pos >= 0)
			_matchedStrLen -= strlen(n);
			
		_newStrLen = str_len - _matchedStrLen;

		if ((_new = (char *)malloc(_newStrLen)) == NULL)
			return "NULL";

		(_new)[_newStrLen+1] = '\0';		

		/* copy sub-string from specified delimiter */
		for (i = 0; i < _newStrLen; ++i)
			(_new)[i] = str[_matchedStrLen +1 + i];
		strcpy(str, _new);
		free (_new);
	}
	
	return str;
}

bool isLeapYear (int year)
{
	if(((year % 4==0) && (year%100 != 0)) || (year % 400 == 0))
	   return true;
	else
		return false;	
}

bool IsLeapYear(int year)	
{					
	if(year%4==0) //必須能被4整除 
	{	
		 if(year%100==0)	
		 {	
				if(year%400==0)
					return	true;//如果以00結尾,還要能被400整除 
				else
					return false;		
		 }
		 else
		 	return true;		
	}
	else
		return false;	
}	

/* ======================(function header)========================
Function Name : Days get_day_code (int year){}
Description : The codes are: day_code (0 = Sun, 1 = Mon, etc.).
Arguments : a year as a decimal number with century.
Return : an user defined type 'Days' value.
written by Jackie Xie
Date : 2011/08/28
================================================================*/
Days get_day_code (int year)
{
	int day_code;
	int x1, x2, x3;
	x1 = (year - 1.)/ 4.0;
	x2 = (year - 1.)/ 100.;
	x3 = (year - 1.)/ 400.;
	day_code = (year + x1 - x2 + x3) %7;
	return day_code;
}

/* ======================(function header)========================
Function Name : int dayOfMonth(datetime dt){}
Description : To convert the day(Sun...Sat) of week(1~5) of 
 month(1~12) into the day of the month as a decimal 
 number(01-31).
Arguments : a user defined type 'datetime' dt.
Return : an interger value which range is from 1 to 31.
written by Jackie Xie
Date : 2011/08/28
================================================================*/
int dayOfMonth(datetime dt)
{
	int days, month;
	Days day_code;

	if(isLeapYear(dt.year))
		years[February] = 29;
	
	//printf("February have %d days in %d\n", years[February], dt.year);
	
	day_code = get_day_code(dt.year);
	for ( month = 1; month < dt.month; month++ )
	{
		/* set day_code for next month to begin */
		day_code = ( day_code + years[month] ) % 7;	
	}
	
	days = (dt.day >= day_code)?(dt.day - day_code + 1)+7*(dt.week-1): (7 - day_code + 1) + dt.day + 7*(dt.week-1);
	
	while(days > years[dt.month])
		days -= 7;
	
	return days;
}

/* ======================(function header)========================
Function Name :t ime_t str2datetime(char *datetime){}
Description : To Convert the string of datetime format into an interger 
 which unit is a time 'second'.
Arguments : char * tz
Return : an integer of type 'time_t '
written by Jackie Xie
Date : 2011/08/29
================================================================*/
time_t str2datetime(char *datetime)
{
	int year, month, day, hour, min, sec;
	struct tm *when;
	time_t tme;
	char tmp_time[32];
	strcpy(tmp_time, datetime);

	sscanf(tmp_time, "%4d-%02d-%02dT%02d:%02d:%02dZ", &year, &month, &day, &hour, &min, &sec);

	time(&tme);
	when = localtime(&tme);
	when->tm_year = year - 1900;
	when->tm_mon = month-1;
	when->tm_mday = day;
	when->tm_hour = hour;
	when->tm_min = min;
	when->tm_sec = sec;

	return(mktime(when));
}

/* ======================(function header)========================
Function Name:int getTZ(char **tz){}
Description : To find the time difference[Coordinated Universal Time
 (UTC)] between GMT and Local time zone.
Arguments : char ** tz
Return : a string with format "[+|-]hh:mm"
written by jackiexie
Date : 2011/06/02
Example :
 int main(int argc, char** argv)
 {
 char *tz;

 getTZ(&tz);
 printf("UTC%s", tz);

 return 0;
 }
================================================================*/
int getTZ(char **tz)
{
	struct tm *tptr;
	char UTC[20];
	time_t secs,l_secs,gmt_secs;
	float utc;
	char *min, *sign;
	int tmp;
	
	time(&secs);
	tptr = localtime(&secs);
	l_secs = mktime(tptr);
	tptr = gmtime(&secs);
	gmt_secs = mktime(tptr);
	utc = l_secs - gmt_secs;
	
	utc = utc/3600.0;
	//utc = -9.9;//-2.5;-3.5;-4.5;-9.5;-12;-10;5.75;8.75;12.75;13.75;14

	if(utc < 0)
		sign = strdup("-");
	else if(utc > 0)
		sign = strdup("+");

	tmp = utc * 60;
	tmp = abs(tmp) % 60;
	
	if(tmp == 30)
		min = strdup("30");
	else if(tmp == 45)
		min = strdup("45");
	else if(tmp != 0)
		min = strdup(itos(tmp));
	else
		min = strdup("00");

	tmp = (int)abs(utc);
	if(tmp <= 14 && tmp >= 10)
		sprintf(UTC, "%s%d:%s", sign, tmp, min);
	else if(tmp < 10 && tmp > 0)
		sprintf(UTC, "%s0%d:%s", sign, tmp, min);
	else
		sprintf(UTC, "00:00");

	*tz = strdup(UTC);
	//printf("%s(%s)\n", UTC, *tz);
	if(*tz == NULL)
		return -1;
	
	free(min);
	free(sign);
	
	return 0;
}

/* ======================(function header)========================
Function Name:int setTZ(char **tz){}
Description : To Setup the system date、time by timezone information.
Arguments : char * tz
Return : a string with format "[+|-]hh:mm"
written by Jackie Xie
Date : 2011/08/18
================================================================*/
int setTZ(char *timezone)
{
	struct tm *tptr;
	struct timeval tv;
	struct timezone tz;
	time_t secs;
	int utc = 0;
	int hsecs, msecs;
	int rc;
	char *sHour = strdup(timezone);
	char *sMin = strdup(timezone);

	(void) time(&secs);
	tptr = localtime(&secs);
	printf("The timezone is 'UTC%s'\n", timezone);
	printf("The current date/time :\n");
	printf(" Date : %02d-%02d-%02d\n", 1900+tptr->tm_year, tptr->tm_mon+1, tptr->tm_mday);
	printf(" Time : %02d:%02d:%02d\n\n", tptr->tm_hour, tptr->tm_min, tptr->tm_sec);

	if(strstr(timezone,":")){
		hsecs = atoi(strcutail(sHour, ":", -100)) * 3600;
		msecs = atoi(strmhead(sMin, ":", -100)) * 60;
	}
	else{
		hsecs = atoi(sHour) * 3600;
		msecs = 0;
	}	
	
	utc = hsecs + msecs;
	 (void) time(&secs);
	
	if(utc==0)
		tptr = localtime(&secs);
	else{
		secs += utc;
		tptr = gmtime(&secs);
	}

	// Make new system time.
	if ((tv.tv_sec = mktime(tptr)) == (time_t)-1)
	{
		printf("Cannot convert system time\n");
	}

	tz.tz_minuteswest = -(secs / 60);	
	tv.tv_usec = 0;
	rc = settimeofday(&tv, &tz);
	if ( rc != 0)
	{
		printf("Cannot set system time\n");
		printf("settimeofday() failed, " "errno = %d\n",errno);
		return -1;
	}
	else
		printf("settimeofday() successful.\n");

	printf("Update timezone:'UTC%s'\n", timezone);
	printf("The new date/time is :\n");
	printf(" Date: %02d-%02d-%02d\n", 1900+tptr->tm_year, tptr->tm_mon+1, tptr->tm_mday);
	printf(" Time: %02d:%02d:%02d\n\n", tptr->tm_hour, tptr->tm_min, tptr->tm_sec);

	free(sMin);
	free(sHour);
	
	return 0;
}

/* ======================(function header)===========================
Function Name:int setTZName(char *tzname){}
Description : To Setup the system date、time by a specified local timezone name which 
 is encoded according to IEEE 1003.1 (POSIX).

 Specifying the Time Zone with TZ

 In POSIX systems, a user can specify the time zone by means of the TZ environment variable. For information about how to set environment variables, see section Environment Variables. The functions for accessing the time zone are declared in `time.h'.

 You should not normally need to set TZ. If the system is configured properly, the default time zone will be correct. You might set TZ if you are using a computer over a network from a different time zone, and would like times reported to you in the time zone local to you, rather than what is local to the computer.

 In POSIX.1 systems the value of the TZ variable can be in one of three formats. With the GNU C library, the most common format is the last one, which can specify a selection from a large database of time zone information for many regions of the world. The first two formats are used to describe the time zone information directly, which is both more cumbersome and less precise. But the POSIX.1 standard only specifies the details of the first two formats, so it is good to be familiar with them in case you come across a POSIX.1 system that doesn't support a time zone information database.

 The first format is used when there is no Daylight Saving Time (or summer time) in the local time zone:

 std offset
 The std string specifies the name of the time zone. It must be three or more characters long and must not contain a leading colon, embedded digits, commas, nor plus and minus signs. There is no space character separating the time zone name from the offset, so these restrictions are necessary to parse the specification correctly.

 The offset specifies the time value you must add to the local time to get a Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east. The hour must be between 0 and 23, and the minute and seconds between 0 and 59.

 The minutes ( mm) and seconds ( ss) are optional. The hour ( hh) shall be required and may be a single digit. The offset following std shall be required. If no offset follows dst, the alternative time is assumed to be one hour ahead of standard time. One or more digits may be used; the value is always interpreted as a decimal number. The hour shall be between zero and 24, and the minutes (and seconds)-if present-between zero and 59. The result of using values outside of this range is unspecified. If preceded by a '-', the timezone shall be east of the Prime Meridian; otherwise, it shall be west (which may be indicated by an optional preceding '+' ).

 For example, here is how we would specify Eastern Standard Time, but without any Daylight Saving Time alternative:

 EST+5
 The second format is used when there is Daylight Saving Time:

 std offset dst [offset],start[/time],end[/time]
 The initial std and offset specify the standard time zone, as described above. The dst string and offset specify the name and offset for the corresponding Daylight Saving Time zone; if the offset is omitted, it defaults to one hour ahead of standard time.

 The remainder of the specification describes when Daylight Saving Time is in effect. The start field is when Daylight Saving Time goes into effect and the end field is when the change is made back to standard time. The following formats are recognized for these fields:

 Jn
 This specifies the Julian day, with n between 1 and 365. February 29 is never counted, even in leap years.
 n
 This specifies the Julian day, with n between 0 and 365. February 29 is counted in leap years.

 Mm.w.d
 This specifies day d of week w of month m. The day d must be between 0 (Sunday) and 6. The week w must be between 1 and 5; week 1 is the first week in which day d occurs, and week 5 specifies the last d day in the month. The month m should be between 1 and 12.
 The time fields specify when, in the local time currently in effect, the change to the other time occurs. If omitted, the default is 02:00:00.

 For example, here is how you would specify the Eastern time zone in the United States, including the appropriate Daylight Saving Time and its dates of applicability. The normal offset from UTC is 5 hours; since this is west of the prime meridian, the sign is positive. Summer time begins on the first Sunday in April at 2:00am, and ends on the last Sunday in October at 2:00am.

 EST+5EDT,M4.1.0/2,M10.5.0/2

Arguments : char * tz
Return : a string with format "std offset dst [offset],start[/time],end[/time]"
written by Jackie Xie
Date : 2011/08/28
===================================================================*/
int setTZName(char *tzname)
{
	char *offsets = strdup(tzname);
	char stz[10]={0};
	char dtz[10]={0};
	char stz_offset[10]={0};
	char dtz_offset[10]={0};
	char *start_dst = NULL;
	char *end_dst = NULL;
	int len, i = -1, chstr = 0, chnum = 0;
	int stdlen = 0, dstlen = 0, sofflen = 0, dofflen = 0;
	char *times, *day, *week, *month, *year, *tmp;
	datetime sdst, edst;
	time_t ptime = 0;
	char data[32];
	
	sdst.ptime = edst.ptime = 0;

	if(strstr(tzname, ","))
	{
		datetime currtime;
		time_t currTime;
		struct tm* pLocalTime=NULL;
	
		times = strdup("00:00:00");
		day = strdup("00");
		week = strdup("0");
		month = strdup("00");
		year = strdup("0000");

		currTime = time(NULL);
		pLocalTime = localtime(&currTime);
		strftime(times, 10 ,"%H:%M:%S", pLocalTime);
		strftime(day, 3 ,"%d", pLocalTime);
		strftime(week, 2 ,"%w", pLocalTime);
		strftime(month, 3 ,"%m", pLocalTime);
		strftime(year, 5, "%Y", pLocalTime);
		
		tmp = strdup(times); currtime.time.hour = atoi(strcutail(tmp, ":", -1));
		tmp = strdup(times); currtime.time.minute = atoi(GetStrBetweenStr(tmp, ":", ":"));
		tmp = strdup(times); currtime.time.second = atoi(strmhead(tmp, ":", -2));
		currtime.day = atoi(day);
		currtime.week = atoi(week);
		currtime.month = atoi(month);
		currtime.year = atoi(year);
		printf("current time is '%4d-%02d-%02dT%02d:%02d:%02dZ'\n", currtime.year, currtime.month, currtime.day, currtime.time.hour, currtime.time.minute, currtime.time.second);

		start_dst = strdup(tzname);
		end_dst = strdup(tzname);
		tmp = strdup(tzname);
		strcutail(offsets, ",", -1);
		//printf("offsets = %s\n", offsets);
		start_dst = strdup(GetStrBetweenStr(tmp, ",", ","));
		if(!strstr(start_dst, "/"))
			sprintf(start_dst, "%s/2", start_dst);
		
		times = strdup(start_dst);
		day = strdup(start_dst);
		week = strdup(start_dst);
		month = strdup(start_dst);
		
		//sdst.time = atoi(strmhead(times, "/", -1));
		tmp = strdup(strmhead(times, "/", -1));
		if(strstr(tmp, ":"))
		{
			times = strdup(tmp); sdst.time.hour = atoi(strcutail(times, ":", -1));
			times = strdup(tmp); printf("times : %s\n", times);
			if(strstr(strmhead(times, ":", -1), ":")) sdst.time.minute = atoi(strcutail(times, ":", -1));
			else sdst.time.minute = atoi(times);
			times = strdup(tmp);
			if(strstr(strmhead(times, ":", -1), ":")) sdst.time.second = atoi(strmhead(times, ":", -1));
			else sdst.time.second = 0;
		}
		else
		{
			sdst.time.hour = atoi(tmp);
			sdst.time.minute = 0;
			sdst.time.second = 0;
		}
			
		sdst.day = atoi(strcutail(strmhead(day, ".", -2), "/", -1));
		sdst.week = atoi(GetStrBetweenStr(week, ".", "."));
		sdst.month = atoi(GetStrBetweenStr(month, "M", "."));

		strmhead(end_dst, ",", -2);
		if(!strstr(end_dst, "/"))
			sprintf(end_dst, "%s/2", end_dst);
		
		times = strdup(end_dst);
		day = strdup(end_dst);
		week = strdup(end_dst);
		month = strdup(end_dst);
		
		//edst.time = atoi(strmhead(times, "/", -1));
		tmp = strdup(strmhead(times, "/", -1));
		if(strstr(tmp, ":"))
		{
			times = strdup(tmp); edst.time.hour = atoi(strcutail(times, ":", -1));
			times = strdup(tmp);
			if(strstr(strmhead(times, ":", -1), ":")) edst.time.minute = atoi(strcutail(times, ":", -1));
			else edst.time.minute = atoi(times);
			times = strdup(tmp);
			if(strstr(strmhead(times, ":", -1), ":")) edst.time.second = atoi(strmhead(times, ":", -1));
			else edst.time.second = 0;
		}
		else
		{
			edst.time.hour = atoi(tmp);
			edst.time.minute = 0;
			edst.time.second = 0;
		}

		edst.day = atoi(strcutail(strmhead(day, ".", -2), "/", -1));
		edst.week = atoi(GetStrBetweenStr(week, ".", "."));
		edst.month = atoi(GetStrBetweenStr(month, "M", "."));
		
		if(sdst.month > edst.month)
		{
			sdst.year = currtime.year;
			edst.year = currtime.year + 1;
		}
		else
			sdst.year = edst.year = currtime.year;

		printf("start daylight saving time is '%4d-%02d-%02dT%02d:%02d:%02dZ'\n", sdst.year, sdst.month, dayOfMonth(sdst), sdst.time.hour, sdst.time.minute, sdst.time.second);
		printf("end daylight saving time is '%4d-%02d-%02dT%02d:%02d:%02dZ'\n", edst.year, edst.month, dayOfMonth(edst), edst.time.hour, edst.time.minute, edst.time.second);
		
		sprintf(data, "%4d-%02d-%02dT%02d:%02d:%02dZ\n", currtime.year, currtime.month,  currtime.day, currtime.time.hour, currtime.time.minute, currtime.time.second);
		currtime.ptime = str2datetime(data);
		//printf("%d\n", (int)currtime.ptime);
		ptime = currtime.ptime;

		sprintf(data, "%4d-%02d-%02dT%02d:%02d:%02dZ\n", sdst.year, sdst.month,  sdst.day, sdst.time.hour, sdst.time.minute, sdst.time.second);
		sdst.ptime = str2datetime(data);
		//printf("%d\n", (int)sdst.ptime);

		sprintf(data, "%4d-%02d-%02dT%02d:%02d:%02dZ\n", edst.year, edst.month,  edst.day, edst.time.hour, edst.time.minute, edst.time.second);
		edst.ptime = str2datetime(data);
		//printf("%d\n", (int)edst.ptime);
		
		free(times); free(tmp);
	}

	len = strlen(offsets);
	
	chstr = 0; chnum = 0;
	while (offsets[++i] != '\0')
	{
		if(isalpha(offsets[i]))
		{
			if(!chstr)
			{
				stz[stdlen] = offsets[i];
				stdlen++ ;
			}
			else
			{
				chnum = 1;
				dtz[dstlen] = offsets[i];
				dstlen++ ;
			}
		}
		else if(isdigit(offsets[i]) || offsets[i] == '+' || offsets[i] == '-' || offsets[i] == ':')
		{
			/* If preceded by a '-', the timezone shall be east of the Prime Meridian; 
 * otherwise, it shall be west (which may be indicated by an optional preceding '+' ).
 * Note: The +,- definition specifies east and west and not addition or subtraction, 
 * so be careful. (UTC+1 translates to <Timezone name>-1) 
 */
			chstr = 1;
			if(!chnum)
			{
				stz_offset[sofflen] = offsets[i];
				sofflen++ ;
			}
			else
			{
				dtz_offset[dofflen] = offsets[i];
				dofflen++ ;
			}
		}
	}
	
	
	{	
		char *shour = strdup(stz_offset);
		char *sminute = strdup(stz_offset);
		int doffset = 0, stzhour = atoi(shour) * (-1);
                stzhour = (strstr(tzname, "GMT") || strstr(tzname, "UTC"))?atoi(shour):atoi(shour) * (-1);
		if(dstlen && !dofflen) doffset = stzhour + 1; else doffset = stzhour;
		
		if(strstr(stz_offset, ":"))
		{
			strcutail(shour, ":", -1);
			strmhead(sminute, ":", -1);
			if(doffset > 0)
				sprintf(dtz_offset, "+%d:%s", doffset, sminute);
			else
				sprintf(dtz_offset, "%d:%s", doffset, sminute);
			if(stzhour > 0)
				sprintf(stz_offset, "+%d:%s", stzhour, sminute);
			else
				sprintf(stz_offset, "%d:%s", stzhour, sminute);
		}
		else
		{
			if(doffset > 0)
				sprintf(dtz_offset, "+%d", doffset);
			else
				sprintf(dtz_offset, "%d", doffset);
			if(stzhour > 0)
				sprintf(stz_offset, "+%d", stzhour);
			else
				sprintf(stz_offset, "%d", stzhour);
		}
		free(shour); free(sminute);
	}

	printf("Standard time zone is '%s%s'.\n", stz, stz_offset);
	if(dstlen) printf("Daylight Saving Time zone is '%s%s'.\n\n", dtz, dtz_offset);
	
	if(ptime >= sdst.ptime && ptime <= edst.ptime)
		setTZ(dtz_offset);
	else
		setTZ(stz_offset);

	free(offsets); free(start_dst); free(end_dst);
	return 0;
}

int main(int argc, char *argv[])
{
	//struct timeval tv;
	char help_msg[1024] = "Usage: tznset [-s <timezone>] [-x <timezone name is encoded according to IEEE 1003.1 (POSIX)>] [-i] [-h]\n\n";
	char *tz, *tzname;
	int c;
	
	strcat(help_msg, "tznset command summary\n");
	strcat(help_msg, "\tznset is a function to setup/get timezone infomation.\n");
	strcat(help_msg, "\t-s:setup datetime for specified timezone.\n");
	strcat(help_msg, "\t\t<timezone>:input format:'<+ | ->xx:xx' (x=[0~9]).\n");
	strcat(help_msg, "\t-x:setup datetime for specified timezone name.\n");
	strcat(help_msg, "\t\t<timezone name>:input format:'std offset dst [offset],start[/time],end[/time]' .\n");
	strcat(help_msg, "\t-i:To get te local timezone information.\n");
	strcat(help_msg, "\t-h:To show this help message.\n");

	while ((c = getopt(argc, argv, "s:x:i0:h0:?0")) != -1)
		switch (c) {
			case 's':
				tz = optarg;
				setTZ(tz);
				break;
			case 'x':
				tzname = optarg;
				setTZName(tzname);
				break;
			case 'i':
				getTZ(&tz);
				printf("本地時區是:UTC%s\n", tz);
				break;
			case 'h':
			case '?':
				fprintf(stderr, "%s", help_msg);
				exit(0);
				break;
			default:
				break;
		}
	return 0;
}

 

To run this program:

For example, we could choice the 'Europe/Lisbon' to setup the system datetime.

The execution result was shown as below:

[ jackie ~/test/opensource/datetime/tz ]# ./tznset -x WET0WEST,M3.5.0/1,M10.5.0
current time is '2011-08-31T11:30:28Z'
start daylight saving time is '2011-03-27T01:00:00Z'
end daylight saving time is '2011-10-30T02:00:00Z'
Standard time zone is 'WET0'.
Daylight Saving Time zone is 'WEST+1'.

The timezone is 'UTC+1'
The current date/time :
        Date : 2011-08-31
        Time : 11:30:28

Cannot set system time
settimeofday() failed, errno = 1
[ jackie ~/test/opensource/datetime/tz ]# sudo ./tznset -x WET0WEST,M3.5.0/1,M10.5.0
Password:
current time is '2011-08-31T11:30:34Z'
start daylight saving time is '2011-03-27T01:00:00Z'
end daylight saving time is '2011-10-30T02:00:00Z'
Standard time zone is 'WET0'.
Daylight Saving Time zone is 'WEST+1'.

The timezone is 'UTC+1'
The current date/time :
        Date : 2011-08-31
        Time : 11:30:34

settimeofday() successful.
Update timezone:'UTC+1'
The new date/time is :
        Date: 2011-08-31
        Time: 04:30:34

[ jackie ~/test/opensource/datetime/tz ]# 

To setup the system date / time by Pacific/Chatham time zone:

Execution result was shown as following beown:

[ jackie ~/test/opensource/datetime/tz ]# sudo ./tznset -x CHAST-12:45CHADT,M10.1.0/2:45,M3.3.0/3:45
current time is '2011-08-31T13:50:52Z'
times : 2:45
start daylight saving time is '2011-10-02T02:45:00Z'
end daylight saving time is '2012-03-18T03:45:00Z'
Standard time zone is 'CHAST+12:45'.
Daylight Saving Time zone is 'CHADT+13:45'.

current ptime = 1314769852
start dst ptime = 1317321900
eended dst ptime = 1330458300

The timezone is 'UTC+12:45'
The current date/time :
        Date : 2011-08-31
        Time : 13:50:52

settimeofday() successful.
Update timezone:'UTC+12:45'
The new date/time is :
        Date: 2011-08-31
        Time: 18:35:52

[ jackie ~/test/opensource/datetime/tz ]#

To setup datetime by 'America/Sao Paulo' timezone:

After running tnzset:

[ jackie ~/test/opensource/datetime/tz ]# sudo ./tznset -x BRT3BRST,M10.3.0/0,M2.3.0/0
Password:
current time is '2011-08-31T14:05:28Z'
start daylight saving time is '2011-10-16T00:00:00Z'
end daylight saving time is '2012-02-19T00:00:00Z'
Standard time zone is 'BRT-3'.
Daylight Saving Time zone is 'BRST-2'.

The timezone is 'UTC-3'
The current date/time :
        Date : 2011-08-31
        Time : 14:05:28

settimeofday() successful.
Update timezone:'UTC-3'
The new date/time is :
        Date: 2011-08-31
        Time: 03:05:28

[ jackie ~/test/opensource/datetime/tz ]#

 

To setup datetime by 'Pacific/Marquesas' timezone:

[ jackie MacBook-Pro ~/tznconfig ]$ sudo ./tznconfig -x `xnvram get Pacific/Marquesas`
Password:
Standard time zone is 'MART9:30'.
The timezone is 'UTC-9:30:00'
The current date/time :
        Date : 2012-04-20
        Time : 16:49:50

hrsec = -32400
minsec = -1800
settimeofday() successful.
Update timezone:'UTC-9:30:00'
The new date/time is :
        Date: 2012-04-19
        Time: 23:19:50

[ jackie MacBook-Pro ~/tznconfig ]$

 

 

Time zone abbreviations

 

AbbreviationFull nameLocationTime zone
A Alpha Time Zone Military UTC + 1 hour
ADT Atlantic Daylight Time Atlantic UTC - 3 hours
ADT Atlantic Daylight Time North America UTC - 3 hours
AFT Afghanistan Time Asia UTC + 4:30 hours
AKDT Alaska Daylight Time North America UTC - 8 hours
AKST Alaska Standard Time North America UTC - 9 hours
ALMT Alma-Ata Time Asia UTC + 6 hours
AMST Armenia Summer Time Asia UTC + 5 hours
AMST Amazon Summer Time South America UTC - 3 hours
AMT Armenia Time Asia UTC + 4 hours
AMT Amazon Time South America UTC - 4 hours
ANAST Anadyr Summer Time Asia UTC + 12 hours
ANAT Anadyr Time Asia UTC + 12 hours
AQTT Aqtobe Time Asia UTC + 5 hours
ART Argentina Time South America UTC - 3 hours
AST Arabia Standard Time Asia UTC + 3 hours
AST Atlantic Standard Time Atlantic UTC - 4 hours
AST Atlantic Standard Time Caribbean UTC - 4 hours
AST Atlantic Standard Time North America UTC - 4 hours
AZOST Azores Summer Time Atlantic UTC
AZOT Azores Time Atlantic UTC - 1 hour
AZST Azerbaijan Summer Time Asia UTC + 5 hours
AZT Azerbaijan Time Asia UTC + 4 hours
B Bravo Time Zone Military UTC + 2 hours
BNT Brunei Darussalam Time Asia UTC + 8 hours
BOT Bolivia Time South America UTC - 4 hours
BRST Brasilia Summer Time South America UTC - 2 hours
BRT Brasília time South America UTC - 3 hours
BST Bangladesh Standard Time Asia UTC + 6 hours
BST British Summer Time Europe UTC + 1 hour
BTT Bhutan Time Asia UTC + 6 hours
C Charlie Time Zone Military UTC + 3 hours
CAST Casey Time Antarctica UTC + 8 hours
CAT Central Africa Time Africa UTC + 2 hours
CCT Cocos Islands Time Indian Ocean UTC + 6:30 hours
CDT Central Daylight Time Australia UTC + 10:30 hours
CDT Cuba Daylight Time Caribbean UTC - 4 hours
CDT Central Daylight Time North America UTC - 5 hours
CEST Central European Summer Time Europe UTC + 2 hours
CET Central European Time Africa UTC + 1 hour
CET Central European Time Europe UTC + 1 hour
CHADT Chatham Island Daylight Time Pacific UTC + 13:45 hours
CHAST Chatham Island Standard Time Pacific UTC + 12:45 hours
CKT Cook Island Time Pacific UTC - 10 hours
CLST Chile Summer Time South America UTC - 3 hours
CLT Chile Standard Time South America UTC - 4 hours
COT Colombia Time South America UTC - 5 hours
CST China Standard Time Asia UTC + 8 hours
CST Central Standard Time Australia UTC + 9:30 hours
CST Central Standard Time Central America UTC - 6 hours
CST Cuba Standard Time Caribbean UTC - 5 hours
CST Central Standard Time North America UTC - 6 hours
CVT Cape Verde Time Africa UTC - 1 hour
CXT Christmas Island Time Australia UTC + 7 hours
ChST Chamorro Standard Time Pacific UTC + 10 hours
D Delta Time Zone Military UTC + 4 hours
DAVT Davis Time Antarctica UTC + 7 hours
E Echo Time Zone Military UTC + 5 hours
EASST Easter Island Summer Time Pacific UTC - 5 hours
EAST Easter Island Standard Time Pacific UTC - 6 hours
EAT Eastern Africa Time Africa UTC + 3 hours
EAT East Africa Time Indian Ocean UTC + 3 hours
ECT Ecuador Time South America UTC - 5 hours
EDT Eastern Daylight Time Australia UTC + 11 hours
EDT Eastern Daylight Time Caribbean UTC - 4 hours
EDT Eastern Daylight Time North America UTC - 4 hours
EDT Eastern Daylight Time Pacific UTC + 11 hours
EEST Eastern European Summer Time Africa UTC + 3 hours
EEST Eastern European Summer Time Asia UTC + 3 hours
EEST Eastern European Summer Time Europe UTC + 3 hours
EET Eastern European Time Africa UTC + 2 hours
EET Eastern European Time Asia UTC + 2 hours
EET Eastern European Time Europe UTC + 2 hours
EGST Eastern Greenland Summer Time North America UTC
EGT East Greenland Time North America UTC - 1 hour
EST Eastern Standard Time Australia UTC + 10 hours
EST Eastern Standard Time Central America UTC - 5 hours
EST Eastern Standard Time Caribbean UTC - 5 hours
EST Eastern Standard Time North America UTC - 5 hours
ET Tiempo del Este Central America UTC - 5 hours
ET Tiempo del Este Caribbean UTC - 5 hours
ET Tiempo Del Este North America UTC - 5 hours
F Foxtrot Time Zone Military UTC + 6 hours
FJST Fiji Summer Time Pacific UTC + 13 hours
FJT Fiji Time Pacific UTC + 12 hours
FKST Falkland Islands Summer Time South America UTC - 3 hours
FKT Falkland Island Time South America UTC - 4 hours
FNT Fernando de Noronha Time South America UTC - 2 hours
G Golf Time Zone Military UTC + 7 hours
GALT Galapagos Time Pacific UTC - 6 hours
GAMT Gambier Time Pacific UTC - 9 hours
GET Georgia Standard Time Asia UTC + 4 hours
GFT French Guiana Time South America UTC - 3 hours
GILT Gilbert Island Time Pacific UTC + 12 hours
GMT Greenwich Mean Time Africa UTC
GMT Greenwich Mean Time Europe UTC
GST Gulf Standard Time Asia UTC + 4 hours
GYT Guyana Time South America UTC - 4 hours
H Hotel Time Zone Military UTC + 8 hours
HAA Heure Avancée de l'Atlantique Atlantic UTC - 3 hours
HAA Heure Avancée de l'Atlantique North America UTC - 3 hours
HAC Heure Avancée du Centre North America UTC - 5 hours
HADT Hawaii-Aleutian Daylight Time North America UTC - 9 hours
HAE Heure Avancée de l'Est Caribbean UTC - 4 hours
HAE Heure Avancée de l'Est North America UTC - 4 hours
HAP Heure Avancée du Pacifique North America UTC - 7 hours
HAR Heure Avancée des Rocheuses North America UTC - 6 hours
HAST Hawaii-Aleutian Standard Time North America UTC - 10 hours
HAT Heure Avancée de Terre-Neuve North America UTC - 2:30 hours
HAY Heure Avancée du Yukon North America UTC - 8 hours
HKT Hong Kong Time Asia UTC + 8 hours
HLV Hora Legal de Venezuela South America UTC - 4:30 hours
HNA Heure Normale de l'Atlantique Atlantic UTC - 4 hours
HNA Heure Normale de l'Atlantique Caribbean UTC - 4 hours
HNA Heure Normale de l'Atlantique North America UTC - 4 hours
HNC Heure Normale du Centre Central America UTC - 6 hours
HNC Heure Normale du Centre North America UTC - 6 hours
HNE Heure Normale de l'Est Central America UTC - 5 hours
HNE Heure Normale de l'Est Caribbean UTC - 5 hours
HNE Heure Normale de l'Est North America UTC - 5 hours
HNP Heure Normale du Pacifique North America UTC - 8 hours
HNR Heure Normale des Rocheuses North America UTC - 7 hours
HNT Heure Normale de Terre-Neuve North America UTC - 3:30 hours
HNY Heure Normale du Yukon North America UTC - 9 hours
HOVT Hovd Time Asia UTC + 7 hours
I India Time Zone Military UTC + 9 hours
ICT Indochina Time Asia UTC + 7 hours
IDT Israel Daylight Time Asia UTC + 3 hours
IOT Indian Chagos Time Indian Ocean UTC + 6 hours
IRDT Iran Daylight Time Asia UTC + 4:30 hours
IRKST Irkutsk Summer Time Asia UTC + 9 hours
IRKT Irkutsk Time Asia UTC + 8 hours
IRST Iran Standard Time Asia UTC + 3:30 hours
IST Israel Standard Time Asia UTC + 2 hours
IST India Standard Time Asia UTC + 5:30 hours
IST Irish Standard Time Europe UTC + 1 hour
JST Japan Standard Time Asia UTC + 9 hours
K Kilo Time Zone Military UTC + 10 hours
KGT Kyrgyzstan Time Asia UTC + 6 hours
KRAST Krasnoyarsk Summer Time Asia UTC + 8 hours
KRAT Krasnoyarsk Time Asia UTC + 7 hours
KST Korea Standard Time Asia UTC + 9 hours
KUYT Kuybyshev Time Europe UTC + 4 hours
L Lima Time Zone Military UTC + 11 hours
LHDT Lord Howe Daylight Time Australia UTC + 11 hours
LHST Lord Howe Standard Time Australia UTC + 10:30 hours
LINT Line Islands Time Pacific UTC + 14 hours
M Mike Time Zone Military UTC + 12 hours
MAGST Magadan Summer Time Asia UTC + 12 hours
MAGT Magadan Time Asia UTC + 11 hours
MART Marquesas Time Pacific UTC - 9:30 hours
MAWT Mawson Time Antarctica UTC + 5 hours
MDT Mountain Daylight Time North America UTC - 6 hours
MHT Marshall Islands Time Pacific UTC + 12 hours
MMT Myanmar Time Asia UTC + 6:30 hours
MSD Moscow Daylight Time Europe UTC + 4 hours
MSK Moscow Standard Time Europe UTC + 3 hours
MST Mountain Standard Time North America UTC - 7 hours
MUT Mauritius Time Africa UTC + 4 hours
MVT Maldives Time Asia UTC + 5 hours
MYT Malaysia Time Asia UTC + 8 hours
N November Time Zone Military UTC - 1 hour
NCT New Caledonia Time Pacific UTC + 11 hours
NDT Newfoundland Daylight Time North America UTC - 2:30 hours
NFT Norfolk Time Australia UTC + 11:30 hours
NOVST Novosibirsk Summer Time Asia UTC + 7 hours
NOVT Novosibirsk Time Asia UTC + 6 hours
NPT Nepal Time Asia UTC + 5:45 hours
NST Newfoundland Standard Time North America UTC - 3:30 hours
NUT Niue Time Pacific UTC - 11 hours
NZDT New Zealand Daylight Time Antarctica UTC + 13 hours
NZDT New Zealand Daylight Time Pacific UTC + 13 hours
NZST New Zealand Standard Time Antarctica UTC + 12 hours
NZST New Zealand Standard Time Pacific UTC + 12 hours
O Oscar Time Zone Military UTC - 2 hours
OMSST Omsk Summer Time Asia UTC + 7 hours
OMST Omsk Standard Time Asia UTC + 6 hours
P Papa Time Zone Military UTC - 3 hours
PDT Pacific Daylight Time North America UTC - 7 hours
PET Peru Time South America UTC - 5 hours
PETST Kamchatka Summer Time Asia UTC + 12 hours
PETT Kamchatka Time Asia UTC + 12 hours
PGT Papua New Guinea Time Pacific UTC + 10 hours
PHOT Phoenix Island Time Pacific UTC + 13 hours
PHT Philippine Time Asia UTC + 8 hours
PKT Pakistan Standard Time Asia UTC + 5 hours
PMDT Pierre & Miquelon Daylight Time North America UTC - 2 hours
PMST Pierre & Miquelon Standard Time North America UTC - 3 hours
PONT Pohnpei Standard Time Pacific UTC + 11 hours
PST Pacific Standard Time North America UTC - 8 hours
PST Pitcairn Standard Time Pacific UTC - 8 hours
PT Tiempo del Pacífico North America UTC - 8 hours
PWT Palau Time Pacific UTC + 9 hours
PYST Paraguay Summer Time South America UTC - 3 hours
PYT Paraguay Time South America UTC - 4 hours
Q Quebec Time Zone Military UTC - 4 hours
R Romeo Time Zone Military UTC - 5 hours
RET Reunion Time Africa UTC + 4 hours
S Sierra Time Zone Military UTC - 6 hours
SAMT Samara Time Europe UTC + 4 hours
SAST South Africa Standard Time Africa UTC + 2 hours
SBT Solomon IslandsTime Pacific UTC + 11 hours
SCT Seychelles Time Africa UTC + 4 hours
SGT Singapore Time Asia UTC + 8 hours
SRT Suriname Time South America UTC - 3 hours
SST Samoa Standard Time Pacific UTC - 11 hours
T Tango Time Zone Military UTC - 7 hours
TAHT Tahiti Time Pacific UTC - 10 hours
TFT French Southern and Antarctic Time Indian Ocean UTC + 5 hours
TJT Tajikistan Time Asia UTC + 5 hours
TKT Tokelau Time Pacific UTC - 10 hours
TLT East Timor Time Asia UTC + 9 hours
TMT Turkmenistan Time Asia UTC + 5 hours
TVT Tuvalu Time Pacific UTC + 12 hours
U Uniform Time Zone Military UTC - 8 hours
ULAT Ulaanbaatar Time Asia UTC + 8 hours
UYST Uruguay Summer Time South America UTC - 2 hours
UYT Uruguay Time South America UTC - 3 hours
UZT Uzbekistan Time Asia UTC + 5 hours
V Victor Time Zone Military UTC - 9 hours
VET Venezuelan Standard Time South America UTC - 4:30 hours
VLAST Vladivostok Summer Time Asia UTC + 11 hours
VLAT Vladivostok Time Asia UTC + 10 hours
VUT Vanuatu Time Pacific UTC + 11 hours
W Whiskey Time Zone Military UTC - 10 hours
WAST West Africa Summer Time Africa UTC + 2 hours
WAT West Africa Time Africa UTC + 1 hour
WDT Western Daylight Time Australia UTC + 9 hours
WEST Western European Summer Time Africa UTC + 1 hour
WEST Western European Summer Time Europe UTC + 1 hour
WET Western European Time Africa UTC
WET Western European Time Europe UTC
WFT Wallis and Futuna Time Pacific UTC + 12 hours
WGST Western Greenland Summer Time North America UTC - 2 hours
WGT West Greenland Time North America UTC - 3 hours
WIB Western Indonesian Time Asia UTC + 7 hours
WIT Eastern Indonesian Time Asia UTC + 9 hours
WITA Central Indonesian Time Asia UTC + 8 hours
WST Western Sahara Summer Time Africa UTC + 1 hour
WST Western Standard Time Australia UTC + 8 hours
WST West Samoa Time Pacific UTC - 11 hours
WT Western Sahara Standard Time Africa UTC
X X-ray Time Zone Military UTC - 11 hours
Y Yankee Time Zone Military UTC - 12 hours
YAKST Yakutsk Summer Time Asia UTC + 10 hours
YAKT Yakutsk Time Asia UTC + 9 hours
YAPT Yap Time Pacific UTC + 10 hours
YEKST Yekaterinburg Summer Time Asia UTC + 6 hours
YEKT Yekaterinburg Time Asia UTC + 5 hours
Z Zulu Time Zone Military UTC

 

Date and Time

travel math

NTP

NTP Server

IEEE Std 1003.1, 2004 Edition

ISO 8601

UNIX時間

Coordinated Universal Time

Time zone abbreviations

Daylight Saving Time – DST

Time Zone and other travel tools

Sources for Time Zone and Daylight Saving Time Data

List of time zones by UTC offset

Time Zone Offset from Universal Time

settimeofday

settimeofday()--Set System Clock

Setting the timezone on OpenWrt

Time & Time Zone Conversion

Time Zone database

List of tz database time zones

tz database

Working with Time Zones

Time Zones on OpenWrt

TimeZone/format selection on OpenWRT

PHP:List of Supported Timezones

Time Synchronisation on OpenWrt

netcwmp

Perl:DateTime-TimeZone

Timezones for humans: an open-source timezone converter

C++ Boost Libraries for timezone

Setup system date/time by timezone in C

tznconfig source files Google code

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Bluelove1968 的頭像
    Bluelove1968

    藍色情懷

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()