Ⅰ java 将时间转换成秒
public int returnSeconde(String instr){
String[] a=instr.splite("\\.");
String[] b=a[0].splite(":");
return Integer.valueOf(b[0])*60*60 + Integer.valueOf(b[1])*60 + Integer.valueOf(b[2]);
}
基本上就是这样了,没有调试过,也没做输入校验,不过基本思路没什么错。
Ⅱ 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中如何取系统时间精确到秒
1 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
2 Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);
3 Date nowTime = new Date(System.currentTimeMillis());
SimpleDateFormat
sdFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String
retStrFormatNowDate = sdFormatter.format(nowTime);
Ⅳ 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中如何获得当前时间并输出:时,分,秒,
import java.util.*;
import java.text.*;
public class TimeTest {
///详细见java.util.SimpleDateFormat;
///java.util.Calendar;
//里面有get(xxFIELD);方法很方便就获取了时,分,秒,毫秒等数值
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");//时:分:秒.毫秒
GregorianCalendar gc = new GregorianCalendar();
System.out.println(sdf.format(gc.getTime()));
////////////////增加2分钟
gc.add(GregorianCalendar.MINUTE, 2);
System.out.println(sdf.format(gc.getTime()));
}
}
Ⅵ java怎么获得得系统时间就是那种一串数字的时间(当前秒数),不要格式输出的
System.out.println(System.currentTimeMillis());
Ⅶ java 中怎么比较两个时间相差的秒数
方法:
java 计算两个时间相差可以用getTime()来获得两个时间的毫秒数,可以这样计算得出两个时间的秒数的相差如下:
public int calLastedTime(Date startDate) {long a = new Date().getTime();long b = startDate.getTime();int c = (int)((a - b) / 1000);return c;}
(7)java当前时间秒数扩展阅读:
1、通过Date类来获取当前时间
Date day=new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(day));
2、通过System类中的currentTimeMillis方法来获取当前时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(df.format(System.currentTimeMillis()));
3、通过Calendar类来获取当前时间
Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);
4、 通过Date类来获取当前时间
Date date = new Date();
String year = String.format("%tY", date);
String month = String.format("%tB", date);
String day = String.format("%te", date);
System.out.println("今天是:"+year+"-"+month+"-"+day);
Ⅷ java如何获取当前时间 年月日 时分秒
//得到long类型当前时间
longl=System.currentTimeMillis();
//new日期对
Datedate=newDate(l);
//转换提日期输出格式
SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-
ddHH:mm:ss");System.out.println(dateFormat.format(date));
(8)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计算当前时间对象与形参传入时间对象之间间隔秒数的方法
当前时间 Date current=new Date(); current.getTime() 减去 传入时间对象.getTime() ,得到的是间隔毫秒数,再除以1000,就是间隔秒数。
Ⅹ java输入时间算秒数
看我滴~~~~~~~~
完全按照楼主所给思路来的:
importjava.util.Scanner;
/**
*Input:
*
*Enteradateinttheformatyyyy/mm/dd;
*
*1999/12/25
*
*Enteratimeintheformathh:mm:ss;
*
*11:03:25
*
*?1)Windows2)Mac
*
*1
*
*Output:
*
*Year:1999Month:12Day:25
*
*Hour:11Minute:3second:25
*
*Totalseconds:39805.0
*
*TheWindowsExceldate/timeis36519.460706018515
*
*EndofProcessing
*
*@authorxiaobo
*
*思路:
*
*1.计算到目前为止的闰年数
*
*leap=1+min(year-?,0)+【(year-?)/4】-【(year-?)/100】+【(year-?+300)/400】
*
*其中【】表示向下取整,?表示1900或1904
*
*2.计算该年到这个月为止的天数
*
*d=【-1.63+(month-1)*30.6】
*
*3.计算总的天数
*
*result=day+(year-?)*365+leap+d
*
*/
publicclassCalculateSeconds{
publicstaticvoidmain(String[]args){
Scannerin=newScanner(System.in);
System.out.println("Enteradateinttheformatyyyy/mm/dd");
Stringymd=in.nextLine();
System.out.println("Enteratimeintheformathh:mm:ss");
Stringhms=in.nextLine();
System.out
.println("?1)Windows2)Mac");
Stringwm=in.nextLine();
String[]arrStr1=ymd.split("/");
String[]arrStr2=hms.split(":");
intyear=Integer.parseInt(arrStr1[0]);
if(wm.equals("1")){
year-=1900;
}elseif(wm.equals("0")){
year-=1904;
}else{
System.err.println("error");
System.exit(-1);
}
intleap=(int)(1+Math.min(year,0)+Math.floor(year/4)
+Math.floor(year/100)+Math.floor((year+300)/400));
intd=(int)Math.floor(-1.63+(Integer.parseInt(arrStr1[1])-1)
*30.6);
intresult=Integer.parseInt(arrStr1[2])+year*365+leap+d;
System.out.println("Year:"+Integer.parseInt(arrStr1[0])+"Month:"
+Integer.parseInt(arrStr1[1])+"Day:"
+Integer.parseInt(arrStr1[2]));
System.out.println("Hour:"+Integer.parseInt(arrStr2[0])+"Minute:"
+Integer.parseInt(arrStr2[1])+"second:"
+Integer.parseInt(arrStr2[2]));
System.out.println("Totalseconds:"
+(Integer.parseInt(arrStr2[0])*3600
+Integer.parseInt(arrStr2[1])*60+Integer
.parseInt(arrStr2[2])));
if(wm.equals("1")){
System.out.print("TheWindowsExceldate/timeis");
}else{
System.out.print("TheMacExceldate/timeis");
}
System.out.println(result+(Integer.parseInt(arrStr2[0])*3600
+Integer.parseInt(arrStr2[1])*60+Integer
.parseInt(arrStr2[2]))/(24*3600.0));
System.out.println("EndofProcessing");
}
}
结果如图: