'TZD'에 해당되는 글 1건

  1. 2008.08.19 [ruby] Ruby의 DateTime 과 W3CDTF 관련
프로그래밍/Ruby2008.08.19 02:07
루비의 DateTime 형식은
문자열 형식으로 찍어보면 다음과 같다.


W3C의 Date Time Format (http://www.w3.org/TR/NOTE-datetime)
형식과 유사하지만 뒷 부분이 다르다.


Different standards may need different levels of granularity in the date and time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions.

The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the "T" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601.

      YYYY (eg 1997)
   Year and month:
      YYYY-MM (eg 1997-07)
   Complete date:
      YYYY-MM-DD (eg 1997-07-16)
   Complete date plus hours and minutes:
      YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
   Complete date plus hours, minutes and seconds:
      YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
   Complete date plus hours, minutes, seconds and a decimal fraction of a
      YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)


     YYYY = four-digit year
     MM   = two-digit month (01=January, etc.)
     DD   = two-digit day of month (01 through 31)
     hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
     mm   = two digits of minute (00 through 59)
     ss   = two digits of second (00 through 59)
     s    = one or more digits representing a decimal fraction of a second
     TZD  = time zone designator (Z or +hh:mm or -hh:mm)

즉 Ruby의 '2008-08-17T01:47:44+0900' 형식이
W3CDTF로 변환되면 '2008-08-17T01:47:44+09:00' 처럼 되야 하는데

뒷 부분의 TZD(time zone designator) 형식이 다르기 때문에

com.adobe.utils.DateUtil.parseW3CDTF( '2008-08-17T01:47:44+0900' ); 을 사용할 때
문제가 발생한다.

DateUtil.parseW3CDTF()  사용말고
DateFormatter 를 사용해 처리한다.
(time zone정보는 파싱할 수 없으므로 따로 해야함 -_-)

해결법2 (Ruby쪽)
시간 출력해주는 부분을 바꿔야 한다.
> require 'date'
> Date.today.to_s
=> "2006-08-21"

> DateTime.now.to_s
=> "2006-08-21T13:08:34-0700"

> DateTime.now..to_s[0..18]
=> "2006-08-21T13:14:15"
# Or use strftime. This example is from ActiveRecord:
user.created_at.strftime("%Y-%m-%d %H:%M:%S")

p.s. 같이 고생한(?) 찬익 쌩큐


Posted by 시난

댓글을 달아 주세요