[英]How to make this sql code in Java
Does anyone know how to implement this SQL code in Java code? 有谁知道如何用Java代码实现此SQL代码?
to_char(to_date(time,'sssss'),'hh24:mi')
Time format is like 36000 in database and then after this sql command it is: 10:00 时间格式类似于数据库中的36000,然后在此sql命令之后为:10:00
I want to make this function work in Java not SQL. 我想使此函数在Java中运行而不是在SQL中运行。
How about this? 这个怎么样? Not tested. 未经测试。
public String toHH24MI(int seconds) {
int hour = seconds/3600;
int min = (seconds%3600)/60;
return String.format("%02d:%02d",hour,min);
}
You can use SimpleDateFormat#format()
to format a Date into a String in a certain pattern. 您可以使用SimpleDateFormat#format()
以某种模式将日期格式化为字符串。
String newstring = new SimpleDateFormat("yyyy-MM-dd").format(date);
System.out.println(newstring); // 2011-01-18
It seems that there is no Java function to do that so i made up my own. 似乎没有Java函数可以做到这一点,所以我自己做了。
public String getTimeFromSeconds(Integer totalSecs) {
int hoursi = totalSecs / 3600;
int minutesi = (totalSecs % 3600) / 60;
String hours="";
String minutes = "";
if( (hoursi > 0 || hoursi == 0) && hoursi < 10)
hours = "0" + hoursi;
else
hours = String.valueOf(hoursi);
if( (minutesi > 0 || minutesi==0) && minutesi < 10)
minutes = "0" + minutesi;
else
minutes = String.valueOf(minutesi);
return hours + ":" + minutes;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.