diff --git a/utilcode/build.gradle b/utilcode/build.gradle index 03821f2b96..14f21ae083 100644 --- a/utilcode/build.gradle +++ b/utilcode/build.gradle @@ -36,5 +36,5 @@ dependencies { testCompile "com.google.truth:truth:$TRUTH_VERSION" testCompile "org.robolectric:robolectric:$ROBOLECTRIC_VERSION" } -//apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle" +apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle" //gradlew bintrayUpload diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/TimeUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/TimeUtils.java index f08b6dcc30..340b555174 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/TimeUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/TimeUtils.java @@ -1032,7 +1032,7 @@ public static Date getDate(Date date, long timeSpan, @TimeConstants.Unit int uni * @return 与当前时间等于时间差的时间戳 */ public static long getMillisByNow(long timeSpan, @TimeConstants.Unit int unit) { - return getNowMills() + timeSpan2Millis(timeSpan, unit); + return getMillis(getNowMills(), timeSpan, unit); } /** @@ -1069,7 +1069,7 @@ public static String getStringByNow(long timeSpan, @TimeConstants.Unit int unit) * @return 与当前时间等于时间差的时间字符串 */ public static String getStringByNow(long timeSpan, @TimeConstants.Unit int unit, String pattern) { - return millis2String(getNowMills() + timeSpan2Millis(timeSpan, unit), pattern); + return getString(getNowMills(), pattern, timeSpan, unit); } /** @@ -1087,7 +1087,7 @@ public static String getStringByNow(long timeSpan, @TimeConstants.Unit int unit, * @return 与当前时间等于时间差的Date */ public static Date getDateByNow(long timeSpan, @TimeConstants.Unit int unit) { - return millis2Date(getNowMills() + timeSpan2Millis(timeSpan, unit)); + return getDate(getNowMills(), timeSpan, unit); } /** diff --git a/utilcode/src/test/java/com/blankj/utilcode/util/TimeUtilsTest.java b/utilcode/src/test/java/com/blankj/utilcode/util/TimeUtilsTest.java index 43ec817cc7..da5819ce8d 100644 --- a/utilcode/src/test/java/com/blankj/utilcode/util/TimeUtilsTest.java +++ b/utilcode/src/test/java/com/blankj/utilcode/util/TimeUtilsTest.java @@ -24,6 +24,7 @@ public class TimeUtilsTest { long millis = 1470991049000L; Date timeDate = new Date(millis); String timeString = "2016-08-12 16:37:29"; + String tomorrowTimeString = "2016-08-13 16:37:29"; String myTimeString = "2016-08-12 16:37:29 中国标准时间"; String timeString0 = "2016-08-12 16:00:00"; String timeString1 = "2016-08-12 17:10:10"; @@ -93,6 +94,11 @@ public void testGetFriendlyTimeSpanByNow() throws Exception { System.out.println(getFriendlyTimeSpanByNow(System.currentTimeMillis() - 2 * TimeConstants.DAY)); } + @Test + public void testGetString() throws Exception { + assertThat(tomorrowTimeString).isEqualTo(getString(millis, 1, TimeConstants.DAY)); + } + @Test public void testIsSameDay() throws Exception { System.out.println(isSameDay(System.currentTimeMillis()));