java把Time类型转为string类型HHmm
要将Time类型转换为String类型,可以使用SimpleDateFormat类将其格式化为指定的格式。以下是一个示例代码:
import java.sql.Time;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] args) {
Time time = new Time(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String timeString = sdf.format(time);
System.out.println(timeString);
}
}
这个示例使用了SimpleDateFormat类将Time类型的时间格式化为"HH:mm"的字符串格式。在这个示例中,我们使用System.currentTimeMillis()获取当前时间。然后,我们创建一个SimpleDateFormat对象并传入要格式化的时间模式。最后,调用format()方法将Time类型的时间转换为字符串格式
原文地址: https://www.cveoy.top/t/topic/hVoe 著作权归作者所有。请勿转载和采集!