diff options
author | laco0416 <laco0416@gmail.com> | 2015-03-11 21:59:15 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2015-03-12 12:46:35 +0900 |
commit | 920c9e6cdf086297afb193c9c0ffa4c4c2430925 (patch) | |
tree | cf980def4fa3b3d3a44936489b582819e9557b9f | |
parent | 11e91ae36315663f3ba0abda5d0752f389f4848a (diff) | |
download | SmileEssence-920c9e6cdf086297afb193c9c0ffa4c4c2430925.tar.gz |
Fix date string for 24-hours style
(cherry picked from commit f7f693661e4b464b6013018e6384b07a411dfcbc)
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/smileessence/util/StringUtils.java | 22 |
1 files changed, 16 insertions, 6 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 436ecdff..efd160c4 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 @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2012-2014 lacolaco.net + * Copyright (c) 2012-2015 lacolaco.net * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,20 +39,30 @@ public class StringUtils Calendar cal = Calendar.getInstance(); cal.setTime(date); - if(cal.get(Calendar.YEAR) == current.get(Calendar.YEAR)) + if(isSameYear(current, cal)) { - if(cal.get(Calendar.DAY_OF_YEAR) == current.get(Calendar.DAY_OF_YEAR)) + if(isSameDay(current, cal)) { - return new SimpleDateFormat("hh:mm:ss").format(date); + return new SimpleDateFormat("HH:mm:ss").format(date); } else { - return new SimpleDateFormat("MM/dd hh:mm:ss").format(date); + return new SimpleDateFormat("MM/dd HH:mm:ss").format(date); } } else { - return new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(date); + return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(date); } } + + private static boolean isSameDay(Calendar current, Calendar cal) + { + return cal.get(Calendar.DAY_OF_YEAR) == current.get(Calendar.DAY_OF_YEAR); + } + + private static boolean isSameYear(Calendar current, Calendar cal) + { + return cal.get(Calendar.YEAR) == current.get(Calendar.YEAR); + } } |