1. 程式人生 > >Java 中時間處理 System.currentTimeMillis()

Java 中時間處理 System.currentTimeMillis()

void ring row mem long long -m throws mes sim

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:ss@SSS");
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);

}

}

Java 中時間處理 System.currentTimeMillis()