提交 5a49f4b6 authored 作者: zgy's avatar zgy

修改时间显示

上级 12fb98ed
......@@ -222,19 +222,24 @@ public class RedisCache<T> {
return hour;
}
public String getHour(String date) {
Integer dt = Integer.parseInt(date);
if (dt < 0) return "0s";
if (dt < 60) return dt + "s";
if (dt < 3600) {
int min = Math.round(dt / 60);
int seconds = Math.round(dt - (min * 60));
return Math.round(dt / 60) + "min" + (seconds == 0 ? "" : seconds + "s");
}
int hour = Math.round(dt / 3600);
int minute = Math.round((dt - (hour * 3600)) / 60);
return hour + "h" + (minute == 0 ? "" : minute + "min");
public String getHour(String time) {
if (Integer.parseInt(time) < 0) {
time = "0";
}
int seconds = Integer.parseInt(time);
int temp = 0;
StringBuffer sb = new StringBuffer();
temp = seconds / 3600;
sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
temp = seconds % 3600 / 60;
sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
temp = seconds % 3600 % 60;
sb.append((temp < 10) ? "0" + temp : "" + temp);
String hour = sb.toString();
return hour;
}
......
......@@ -241,4 +241,15 @@ public class PayTest {
BigDecimal b=new BigDecimal("0");
System.out.println(b!=null);
}
@Test
public void test01(){
String hour="00:00:0-1";
System.out.println(hour.contains("-1"));
if (hour.contains("-1")) {
hour.substring(0,7);
hour=hour+"0";
}
System.out.println(hour);
}
}
......@@ -552,27 +552,7 @@ public class ZionApplicationTests {
System.out.println(hour);
}
public String getHour(String date) {
Integer dt = Integer.parseInt(date);
if (dt < 0) return "0s";
if (dt < 60) return dt + "s";
if (dt < 3600) {
int min = Math.round(dt / 60);
int seconds = Math.round(dt - (min * 60));
return Math.round(dt / 60) + "min" + (seconds == 0 ? "" : seconds + "s");
}
int hour = Math.round(dt / 3600);
int minute = Math.round((dt - (hour * 3600)) / 60);
return hour + "h" + (minute == 0 ? "" : minute + "min");
// //分钟
// Integer dt = Integer.parseInt(date) ;
// if (dt < 60) return dt + "分钟";
// int hour = Math.round(dt / 60);
// int minute = Math.round(dt - (hour * 60));
// return hour + "小时" + (minute == 0 ? "" : minute + "分钟");
}
@Test
public void test01() {
......@@ -584,4 +564,28 @@ public class ZionApplicationTests {
System.out.println(orderRedisCache.expire("order_detf28b71d685a34c528180782520fef886"));
}
@Test
public void test02() {
String str = "-1";
String hour = getHour(str);
System.out.println(hour);
}
public String getHour(String time) {
if(Integer.parseInt(time)<0){
time="0";
}
int seconds = Integer.parseInt(time);
int temp = 0;
StringBuffer sb = new StringBuffer();
temp = seconds / 3600;
sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
temp = seconds % 3600 / 60;
sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
temp = seconds % 3600 % 60;
sb.append((temp < 10) ? "0" + temp : "" + temp);
return sb.toString();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论