linux timezone 본문

카테고리 없음

linux timezone

keydisk 2013. 7. 15. 19:58

1. 리눅스에서 타임존을 설정하기 위해서는 'tzselect' 명령어를 이용하거나..

2 . [root@linux ~]# ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime 와 같은 명령어를 사용하여 타임존 설정이 가능하다.

3.  - /etc/default/rcS 의 파일중에서 UTC=no 로 한다.
    - sudo dpkg-reconfigure tzdata 명령에서 원하는 지역과 도시를 선택한다.

/////////////////////////////

만약 4bytes의 time_t 값을 그대로 주고 받는 다면, 이 값을 UTC로 봐도 됩니다.

즉, time 함수에서 얻어지는 time_t 값은 locale에 대한 정보는 없습니다.
영국,한국,미국 어디서든지 절대적으로 같은 시간에 호출했을 때,
같은 값을 리턴합니다.

이 time_t 값을 가지고 localtime의 함수로 struct tm 형태로 변환했을 때,
local에 대한 정보가 들어가게되죠...

 

//////////////////////////////

 

UTC (Universal Time Coordinated 협정 세계시(時))

협정 세계시는 국제 사회가 사용하는 과학적 시간의 표준입니다.
1972년 1월 1일부터 시행된 협정세계시에서는 67년 국제도량형총회가 정한 세슘원자의 진동수에 의거한 초의 길이가 그 기준(원자초)으로 쓰인다. 그 때까지 시간의 기준으로는 지구의 자전에 의한 평균태양시와 지구의 공전에 의한 태양년에서 산출한 초의 길이가 쓰였다. 그리니치표준시(GMT)는 원래 평균태양시를 기준으로 한 것이었다. 따라서 원자시계를 표준으로 하면서부터 GMT라는 명칭이 실체(實體)를 바르게 나타내지 못하는 불합리한 점이 생겼다. 이러한 문제를 없애기 위해서 1978년 국제무선통신자문위원회(CCIS) 총회는 통신분야에서는 금후 그리니치평균시를 협정세계시(UTC)로 바꾸어 쓰자는 권고안을 채택하였다.

//////////////////////////////////////////

 

 

Get the system time.

time_t time(
   time_t *timer 
);
__time64_t _time64(
   __time64_t *timer 
);

Parameters

timer
Pointer to the storage location for time.

Return Value

Return the time in elapsed seconds. There is no error return.

A call to time or _time64 can fail, however, if the date passed to the function is:

  • Before midnight, January 1, 1970.
  • After 19:14:07, January 18, 2038, UTC (using time and time_t).
  • After 23:59:59, December 31, 3000, UTC (using _time64 and __time64_t).

Remarks

The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC), according to the system clock. The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored.

Requirements

Routine Required header Compatibility
time <time.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_time64 <time.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_times.c
/* This program demonstrates these time and date functions:
 *      _time64         _ftime64        _ctime64     asctime
 *      _localtime64    _gmtime64       _mktime64    _tzset
 *      _strtime        _strdate        strftime
 *
 * Also the global variable:
 *      _tzname
 */

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

int main()
{
    char tmpbuf[128], ampm[] = "AM";
    __time64_t ltime;
    struct __timeb64 tstruct;
    struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

    /* Set time zone from TZ environment variable. If TZ is not set,
     * the operating system is queried to obtain the default value 
     * for the variable. 
     */
    _tzset();

    /* Display operating system-style date and time. */
    _strtime( tmpbuf );
    printf( "OS time:\t\t\t\t%s\n", tmpbuf );
    _strdate( tmpbuf );
    printf( "OS date:\t\t\t\t%s\n", tmpbuf );

    /* Get UNIX-style time and display as number and string. */
    _time64( &ltime );
    printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
    printf( "UNIX time and date:\t\t\t%s", _ctime64( &ltime ) );

    /* Display UTC. */
    gmt = _gmtime64( &ltime );
    printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

    /* Convert to time structure and adjust for PM if necessary. */
    today = _localtime64( &ltime );
    if( today->tm_hour >= 12 )
    {
   strcpy( ampm, "PM" );
   today->tm_hour -= 12;
    }
    if( today->tm_hour == 0 )  /* Adjust if midnight hour. */
   today->tm_hour = 12;

    /* Note how pointer addition is used to skip the first 11 
     * characters and printf is used to trim off terminating 
     * characters.
     */
    printf( "12-hour time:\t\t\t\t%.8s %s\n",
       asctime( today ) + 11, ampm );

    /* Print additional time information. */
    _ftime64( &tstruct );
    printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
    printf( "Zone difference in hours from UTC:\t%u\n", 
             tstruct.timezone/60 );
    printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
    printf( "Daylight savings:\t\t\t%s\n", 
             tstruct.dstflag ? "YES" : "NO" );

    /* Make time for noon on Christmas, 1993. */
    if( _mktime64( &xmas ) != (__time64_t)-1 )
   printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

    /* Use time structure to build a customized time string. */
    today = _localtime64( &ltime );

    /* Use strftime to build a customized time string. */
    strftime( tmpbuf, 128,
         "Today is %A, day %d of %B in the year %Y.\n", today );
    printf( tmpbuf );
}

Sample Output

OS time:                                14:15:49
OS date:                                02/07/02
Time in seconds since UTC 1/1/70:       1013120149
UNIX time and date:                     Thu Feb 07 14:15:49 2002
Coordinated universal time:             Thu Feb 07 22:15:49 2002
12-hour time:                           02:15:49 PM
Plus milliseconds:                      455
Zone difference in hours from UTC:      8
Time zone name:                         Pacific Standard Time
Daylight savings:                       NO
Christmas                               Sat Dec 25 12:00:00 1993

Today is Thursday, day 07 of February in the year 2002.