Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shun0102/3168088 to your computer and use it in GitHub Desktop.
Save shun0102/3168088 to your computer and use it in GitHub Desktop.
data-config.xmlの設定
<field column="ts" name="ts" dateTimeFormat="yyyy-MM-dd hh:mm:ss" locale="ja" />
以下の様な対応で日付が変換される
2012-03-02 00:00:00 => 2012-03-02T15:00:00Z
2012-03-03 12:00:00 => 2012-03-02T15:00:00Z
2012-03-03 00:00:00 => 2012-03-02T15:00:00Z
2012-03-03 12:00:01 => 2012-03-02T15:00:01Z
2012-03-03 00:46:43 => 2012-03-02T15:46:43Z
2012-03-03 00:00:04 => 2012-03-02T15:00:04Z
@johtani
Copy link

johtani commented Jul 24, 2012

"hh"が12時間表記だったからずれたみたいですね。
public class SimpleDateFormatSample {

public static void main(String args[]){

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.JAPAN);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf2.setTimeZone(TimeZone.getTimeZone("GMT"));
String[] input = {
    "2012-03-02 00:00:00",
    "2012-03-03 12:00:00",
    "2012-03-03 00:00:00",
    "2012-03-03 12:00:01",
    "2012-03-03 00:46:43",
    "2012-03-03 00:00:04"};

  for(String tmp : input){
    try{
      System.out.println(tmp+" => "+sdf2.format(sdf.parse(tmp)));
    }catch(ParseException pe){
      System.err.println("parse error");
    }
  }

}

}
この出力結果が一緒になりましたよ。

@johtani
Copy link

johtani commented Jul 24, 2012

って、あれ、1件目の出力結果が違うなぁ。
2012-03-02 00:00:00 => 2012-03-01T15:00:00
2012-03-03 12:00:00 => 2012-03-02T15:00:00
2012-03-03 00:00:00 => 2012-03-02T15:00:00
2012-03-03 12:00:01 => 2012-03-02T15:00:01
2012-03-03 00:46:43 => 2012-03-02T15:46:43
2012-03-03 00:00:04 => 2012-03-02T15:00:04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment