diff options
author | rhenium <rhenium@rhe.jp> | 2015-03-10 21:26:48 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2015-03-10 21:26:48 +0900 |
commit | f1826dfe8a75e0ed3b42b25657d595a13412ecfb (patch) | |
tree | 67a48504809fb7be581fb1b035adfccc07718a56 /app/src/main/java/net/lacolaco/smileessence | |
parent | d5be67b763ce1560a74ee1372855ab364497a458 (diff) | |
download | SmileEssence-f1826dfe8a75e0ed3b42b25657d595a13412ecfb.tar.gz |
Fix date formatting in StringUtils.dateToString
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence')
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/smileessence/util/StringUtils.java | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/smileessence/util/StringUtils.java b/app/src/main/java/net/lacolaco/smileessence/smileessence/util/StringUtils.java index dcb15aee..b7503614 100644 --- a/app/src/main/java/net/lacolaco/smileessence/smileessence/util/StringUtils.java +++ b/app/src/main/java/net/lacolaco/smileessence/smileessence/util/StringUtils.java @@ -24,6 +24,7 @@ package net.lacolaco.smileessence.util; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -35,29 +36,22 @@ public class StringUtils public static String dateToString(Date date) { Calendar cal = Calendar.getInstance(); - Calendar calToday = Calendar.getInstance(); - cal.setTime(date); - int y = cal.get(Calendar.YEAR); - int m = cal.get(Calendar.MONTH); - int d = cal.get(Calendar.DATE); - int h = cal.get(Calendar.HOUR_OF_DAY); - int min = cal.get(Calendar.MINUTE); - int s = cal.get(Calendar.SECOND); - - StringBuilder builder = new StringBuilder(); - - if(cal.get(Calendar.YEAR) != calToday.get(Calendar.YEAR)) + if(cal.get(Calendar.YEAR) == Calendar.getInstance().get(Calendar.YEAR)) { - builder.append(y).append("/"); + if(cal.get(Calendar.DAY_OF_YEAR) == Calendar.getInstance().get(Calendar.DAY_OF_YEAR)) + { + return new SimpleDateFormat("hh:mm:ss").format(date); + } + else + { + return new SimpleDateFormat("MM/dd hh:mm:ss").format(date); + } } - if(cal.get(Calendar.DAY_OF_YEAR) != calToday.get(Calendar.DAY_OF_YEAR)) + else { - builder.append(String.format("%02d", m + 1)).append("/").append(String.format("%02d", d)).append(" "); + return new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(date); } - builder.append(String.format("%02d", h)).append(":").append(String.format("%02d", min)).append(":").append(String.format("%02d", s)); - - return builder.toString(); } } |