import org.testng.annotations.Test;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date; public class TestDate { @Test public void test01() throws ParseException { Date dt= new Date(); long s=System.currentTimeMillis(); long long1= 1533954986837L; SimpleDateFormat dtf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dtf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:[email protected]"); String sdate =dtf1.format(long1); System.out.println(sdate); System.out.println(dtf.format(dt)); System.out.println(dtf1.format(dt)); System.out.println(dtf1.format(dt).toString()); // Date -> String Date date = new Date(System.currentTimeMillis()); System.out.println(dtf.format(date)); // String -> Date String timeString = "2018-08-11 11:44:27"; Date newDate = dtf.parse(timeString); System.out.println(newDate); } }
原文地址:https://www.cnblogs.com/qianjinyan/p/9459198.html
时间: 2024-11-07 08:19:55