fyqt.net
当前位置:首页 >> jAvA秒转换成天时分秒 >>

jAvA秒转换成天时分秒

我刚写的你看看把 public class h { public static void main(String args[]){ System.out.print( cal(3670)); } public static String cal(int second){ int h = 0; int d = 0; int s = 0; int temp = second%3600; if(second>3600){ h= second...

public static void main(String[] args){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(sdf.format(new Date())); SimpleDateFormat sdf2 = new SimpleDateFormat("mm:ss"); System.out.println(s...

string time="h时mm分ss秒"; long s=Integer.parseInt(time.substring(0,time.indexOf("时")))*3600; //小时 s+=Integer.parseInt(time.substring(time.indexOf("时")+1,time.indexOf("分")))*60; //分钟 s+=Integer.parseInt(time.substring(ti...

new一个date就好了,转成时间的话想怎么操作都可以 Date(毫秒数)

小时:h=time/3600(整除) 分钟:m=(time-h*3600)/60 (整除) 秒:s=(time-h*3600) mod 60 (取余)

public static String mSec2hms(Long mSec) {Long diffTime = mSec / 1000L;StringBuilder stringBuilder = new StringBuilder();for(int i = 2; i > 0; i --){Long modTime = diffTime % 60;stringBuilder.insert(0, modTime + (i % 2 == 1 ? "...

Date类有一个getTime()可以换回秒数,例如: public class DateToSecond{ public static void main(String[] args) { Date date = new Date(System.currentTimeMillis()); System.out.println(date.getTime()); }}

//得到long类型当前时间long l = System.currentTimeMillis();//new日期对象Date date = new Date(l);//转换提日期输出格式SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");System.out.println(dateFormat.format(d...

long time = 12471346813; Date date = new Date(time); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String dateStr = sdf.format(date); System.out.println(dateStr); 以上代码复制到main方法中执行下。

import java.util.Scanner; public class Convert{ public static void main(String[] args){ System.out.println("请输入时分秒,格式为hh:mi:ss"); Scanner input=new Scanner(System.in); String s=input.next(); int index1=s.indexOf(":");...

网站首页 | 网站地图
All rights reserved Powered by www.fyqt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com