String str = "2014-01-01 12:12:12"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = format.parse(str); System.out.println(date); System.out.println(date.getTime()); 再链接一个其他的 http://zhi...
毫秒转换为日期 public static void main(String[] args) { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); long now = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMi...
这样就可以: public static void main(String[] args) { Date date = new Date(); Long time = date.getTime(); System.out.println(time); Date d = new Date(time); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); System.out....
java中可以使用calendar类,如下代码: 毫秒转换为日期 public static void main(String[] args) { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); long now = System.currentTimeMillis(); Calendar calendar = Calenda...
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("yyy...
Date类有一个getTime()可以换回秒数,例如: public class DateToSecond{ public static void main(String[] args) { Date date = new Date(System.currentTimeMillis()); System.out.println(date.getTime()); }}
SimpleDateFormat str = new SimpleDateFormat("yyyy-MM");//时间格式 Date date = new Date(); //当前时间 String string = str.format(date); System.out.println(string);
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...
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方法中执行下。