How to parse DateTime property from AppEngine in Java (Android)?

后端 未结 2 1362
傲寒
傲寒 2021-01-13 19:06

I need to parse DateTime string coming from AppEngine in Java (Android). The string looks like this: 2011-07-26 17:21:00+01:00. Is it some standard format? Is t

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 19:49

    What can be simpler than SimpleDateFormat in that case? You just have to get rid of that last nasty : in the timezone part.

    Edit: The format is very close to a standard format.

    This will get rid of the last nasty :, and parse the date:

    String data = "2011-07-26 17:21:00+01:00";
    data = data.replaceFirst("(.*):(..)", "$1$2");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ssZZZ");
    Date parse = formatter.parse(data);
    System.out.println("Got " + parse);
    

提交回复
热议问题