1. java 毫秒转换时间
时间除以1000转换成秒,对60取余就是秒数,除以60后再对60取余是分,除以60后再对24取余是小时
2. java 我获得单位为毫秒的当前时间,如何转化成年月日小时分格式
import java.util.*;
import java.text.SimpleDateFormat;
public class test
{
public static void main (String args[])
{
Date d = new Date();
long longtime = d.getTime();
System.out.println(longtime);
//你获得的是上面的long型数据吧
String time = d.toLocaleString();
//你可以简单的得到本地化时间,本来就是String类型的就不用转换了
System.out.println(time);
//也可以自己用SimpleDateFormat这个函数把它变成自己想要的格式,注意需要import java.text.SimpleDateFormat;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(longtime));
}
}
3. Java:知道一个1970至今的毫秒数,如何转换为时间呢
publicclassDemo{
publicstaticvoidmain(String[]args)throwsException{
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");
System.out.println(sdf.format(Long.parseLong("1404955893000")));
}
}
4. Java 如何根据现在的时间毫秒来计算时间的公式(不想用原有的类)
特意写了一个 你看看是不是这个意思
publicstaticvoidmain(String[]args){
inttimezone=8;
longtimeMillis=newDate().getTime();//1970
longtotalSeconds=timeMillis/1000;
totalSeconds+=60*60*timezone;
intsecond=(int)(totalSeconds%60);//秒
longtotalMinutes=totalSeconds/60;
intminute=(int)(totalMinutes%60);//分
longtotalHours=totalMinutes/60;
inthour=(int)(totalHours%24);//时
inttotalDays=(int)(totalHours/24);
int_year=1970;
intyear=_year+totalDays/366;
intmonth=1;
intday=1;
intdiffDays;
booleanleapYear;
while(true){
intdiff=(year-_year)*365;
diff+=(year-1)/4-(_year-1)/4;
diff-=((year-1)/100-(_year-1)/100);
diff+=(year-1)/400-(_year-1)/400;
diffDays=totalDays-diff;
leapYear=(year%4==0)&&(year%100!=0)||(year%400==0);
if(!leapYear&&diffDays<365||leapYear&&diffDays<366){
break;
}else{
year++;
}
}
int[]monthDays;
if(diffDays>=59&&leapYear){
monthDays=newint[]{-1,0,31,60,91,121,152,182,213,244,274,305,335};
}else{
monthDays=newint[]{-1,0,31,59,90,120,151,181,212,243,273,304,334};
}
for(inti=monthDays.length-1;i>=1;i--){
if(diffDays>=monthDays[i]){
month=i;
day=diffDays-monthDays[i]+1;
break;
}
}
System.out.println(year);
System.out.println(month);
System.out.println(day);
System.out.println(hour);
System.out.println(minute);
System.out.println(second);
}
5. 毫秒时间怎么转换为普通时间 java
TimeSpan ts = new TimeSpan(1251790200000*10);
ts.Days表示对应的天数
ts.Hours表示对应的小时数,
依次推类.
注意:
// Parameters:
// ticks:
// A time period expressed in 100-nanosecond units.
public TimeSpan(long ticks);
你还可以用DateTime类型去Add这个类型的变量,得到加减后的时间.
6. java中怎样把毫秒转成时间类型
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Cat {
public static void main(String[] args) throws ParseException {
String str = "201104141302";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmm");
long millionSeconds = sdf.parse(str).getTime();//毫秒
System.out.println(millionSeconds);
}
}