日期:2014-05-20 浏览次数:20771 次
String date = "Jan 10 19:19:28 2012"; SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy"); long currdate = formatter.parse(date).getTime();
public static void main(String[] args) { String date = "Jan 10 19:19:28 2012"; long d = Date.parse(date); System.out.println(d); SimpleDateFormat formatter = new SimpleDateFormat( "yyyy MM dd HH:mm:SS"); String currdate; currdate = formatter.format(d); System.out.println(currdate); }
------解决方案--------------------
public class TestDate { public static void main(String[] args) throws Exception { String date = "05 02 12:12:12 2012"; SimpleDateFormat formatter = new SimpleDateFormat("MM dd HH:mm:ss yyyy"); long currdate = formatter.parse(date).getTime(); System.out.println(currdate); } }
------解决方案--------------------
import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] aa) { SimpleDateFormat dateformat1 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss E"); String a1 = dateformat1.format(new Date()); System.out.println("时间2:" + a1); System.out.println(new Date().getYear() + 1900); SimpleDateFormat dateformat2 = new SimpleDateFormat( "yyyy年MM月dd日 HH时mm分ss秒 E "); String a2 = dateformat2.format(new Date()); System.out.println("时间2:" + a2); } }
------解决方案--------------------
public class TestDate { public static void main(String[] args) throws Exception { String str="Jan 02 12:12:12 2012"; SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy",Locale.ENGLISH); Date ts = formatter.parse(str); SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy MM HH:mm:SS"); System.out.print(formatter1.format(ts)); } }
------解决方案--------------------