导航:首页 > 编程语言 > java系统当前时间毫秒

java系统当前时间毫秒

发布时间:2022-12-13 05:26:58

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));
}
}

Ⅱ java怎么获取当前系统时间 毫秒数

首先获取当前时间:

java.util.Date nowdate = new java.util.Date();

2/2

然后如果你想时间的格式和你想用的时间格式一致 那么就要格式化时间了SimpleDateFormat 的包在java.text包下SimpleDateFormat

sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") //年月日 时分秒

String t = sdf.parse(nowdate);

Ⅲ java如何获取当前时间 年月日 时分秒

//得到long类型当前时间

longl=System.currentTimeMillis();

//new日期对

Datedate=newDate(l);

//转换提日期输出格式

SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-

ddHH:mm:ss");System.out.println(dateFormat.format(date));

(3)java系统当前时间毫秒扩展阅读

package com.ob;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public class DateTest {

public static void main(String[] args) throws ParseException {

Calendar now = Calendar.getInstance();

System.out.println("年: " + now.get(Calendar.YEAR));

System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");

System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));

System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));

System.out.println("分: " + now.get(Calendar.MINUTE));

System.out.println("秒: " + now.get(Calendar.SECOND));

System.out.println("当前时间毫秒数:" + now.getTimeInMillis());

System.out.println(now.getTime());

Date d = new Date();

System.out.println(d);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateNowStr = sdf.format(d);

System.out.println("格式化后的日期:" + dateNowStr);

String str = "2012-1-13 17:26:33";

//要跟上面sdf定义的格式一样
Date today = sdf.parse(str);

System.out.println("字符串转成日期:" + today);
}
}

Ⅳ JAVA中如何获取毫秒和微秒数

一、获取毫秒数的代码:

微秒使用System.nanoTime()方法:如果Java程序需要高精度的计时,如1毫秒或者更小,使用System.nanoTime()方法,可以满足需求。

(4)java系统当前时间毫秒扩展阅读:

获取微秒函数System.nanoTime() 的隐患:

System.currentTimeMillis() 起始时间是基于 1970.1.1 0:00:00 这个确定的时间的,而System.nanoTime()是基于cpu核心的时钟周期来计时,它的开始时间是不确定的。

但是在多核处理器上,由于每个核心的开始时间不确定,那么

“long start = System.nanoTime();String ip = Utilities.getIpByUrl(url);long cost = System.nanoTime() - start;”

这段代码有可能会运行在两个不同的cpu核心上,从而导致得到的结果完全不符逻辑。

Ⅳ java 怎么获取指定时间的毫秒值如(2012-5-5)

DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
try {
java.util.Date dateTime = format.parse("2012-05-05");
long time=dateTime.getTime();
System.out.println("Time:"+time);
} catch (ParseException e) {
e.printStackTrace();
}
时间如果是Date类型直接getTime()就可以...如果是String类型就用上面的代码转成Date然后取毫秒值.

Ⅵ JAVA如何获取当前小时的毫秒数呢是当前小时,比如2014-03-04 下午16:00:00的毫秒数

大写的s表示毫秒数

你的这个可以这么写

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd aHH:mm:ss:SSS");

System.out.println(dateFormatGmt.format(new Date()));

输出2014-03-04 下午18:13:05:627

这个627就是对应那个SSS,也就是当前毫秒数

Ⅶ java语言中使用 那System.current.TimeMillis过得当前毫秒数,是从199

从1970年到现在的毫秒数
Integer 在JAVA内用32位表示,因此32位能表示的最大值是2147483647。另外1年365天的总秒数是 31536000,2147483647/31536000 = 68.1,也就是说32位能表示的最长时间是68年,从1970年开始的话,加上68.1,实际最终到2038年01月19日03时14分07秒,便会到 达最大时间,过了这个时间点,所有32位操作系统时间便会变为10000000 00000000 00000000 00000000,算下来也就是1901年12月13日20时45分52秒,这样便会出现时间回归的现象,很多软件便会运行异常了。
到 这里,我想问题的答案已经显现出来了,那就是:因为用32位来表示时间的最大间隔是68年,而最早出现的UNIX操作系统考虑到计算机产生的年代和应用的 时限综合取了1970年1月1日作为UNIX TIME的纪元时间(开始时间),至于时间回归的现象相信随着64为操作系统的产生逐渐得到解决,因为用64位操作系统可以表示到 292,277,026,596年12月4日15时30分08秒,相信我们的N代子孙,哪怕地球毁灭那天都不用愁不够用了,因为这个时间已经是千亿年以后 了。

Ⅷ java中如何将Timestamp转换为毫秒数

我写了一个把当前时间转换为毫秒数的例子,你参考一下,我这运行没问题:

package test;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author Administrator
*当前时间转换为毫秒数
*/
public class DeclareTimer {

public static void main(String[] args) throws ParseException {
//获取当前时间
Timestamp t = new Timestamp(new Date().getTime());
System.out.println("当前时间:"+t);
//定义时间格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
String str = dateFormat.format(t);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmm");
//此处转换为毫秒数
long millionSeconds = sdf.parse(str).getTime();// 毫秒
System.out.println("毫秒数:"+millionSeconds);
}
}

Ⅸ 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);
}

Ⅹ 怎么在java里获取带有毫秒的时间

1.

long java.util.Date.getTime()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this Date object.

如上JDK文档说,在Date对象上用getTime()获得自1970年1月1日以来的毫秒数。

2.

System.currentTimeMillis(); 这个方法获取当前时间的毫秒数。

3.

以下实例代码把通过毫秒数相减算的目前距2014-10-01 00:00:00的天数。

publicclassTest{

publicstaticvoidmain(String[]args)throwsParseException{
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");
Stringstart="2014-10-0100:00:00";
//得到毫秒数
longtimeStart=sdf.parse(start).getTime();
longjustNow=System.currentTimeMillis();
//两个日期想减得到天数
longdayCount=(justNow-timeStart)/(24*3600*1000);
System.out.println(dayCount);
}
}

输出

25

阅读全文

与java系统当前时间毫秒相关的资料

热点内容
怎么批量有顺序的命名文件夹 浏览:209
杭州程序员健身 浏览:17
dvd光盘存储汉子算法 浏览:758
苹果邮件无法连接服务器地址 浏览:963
phpffmpeg转码 浏览:672
长沙好玩的解压项目 浏览:145
专属学情分析报告是什么app 浏览:564
php工程部署 浏览:833
android全屏透明 浏览:737
阿里云服务器已开通怎么办 浏览:803
光遇为什么登录时服务器已满 浏览:302
PDF分析 浏览:486
h3c光纤全工半全工设置命令 浏览:143
公司法pdf下载 浏览:383
linuxmarkdown 浏览:350
华为手机怎么多选文件夹 浏览:683
如何取消命令方块指令 浏览:350
风翼app为什么进不去了 浏览:779
im4java压缩图片 浏览:362
数据查询网站源码 浏览:151