[英]extract date to string from a json date string
Android程式設計。 我有一個json從數據庫返回日期作為字符串。 如何使用Joda或任何其他庫從字符串中提取日期為這種格式mm / dd / yy。 這是字符串2012-05-22T00:00:00
這是ISO8601日期格式,所以你可以去jodas:
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
DateTime dt = fmt.parseDateTime(strInputDateTime);
之后,只需格式化DateTime對象:
DateTimeFormatter fmt2 = DateTimeFormat.forPattern("MM/dd/yyyy");
String myDate = fmt2.print(dt)
此信息來自http://joda-time.sourceforge.net/userguide.html#Standard_Formatters
使用標准JDK,您可以使用SimpleDateFormat
Date parsedDateInstance = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(dateString);
String formattedDate = new SimpleDateFormat("MM/dd/yyyy").format(dateInstance);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.