Java提取Timestamp中的年、月、日、时、分、秒,示例代码如下:
import java.util.Date;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
public class FormatDateTimestamp {
public static void main(String[] args) throws ParseException{
try{
String dateString = "2016-02-21 12:03:26.125";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS",Locale.ENGLISH); // hh 也可以换成 kk
dateFormat.setLenient(false);
Date timeDate = dateFormat.parse(dateString); // util类型
Timestamp dateTime = new Timestamp(timeDate.getTime()); // Timestamp类型, timeDate.getTime()返回一个 long 型
System.out.println(dateTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss.SSS",Locale.ENGLISH); // HH 也可以换成 kk
Date dat
import java.util.Date;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
public class FormatDateTimestamp {
public static void main(String[] args) throws ParseException{
try{
String dateString = "2016-02-21 12:03:26.125";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS",Locale.ENGLISH); // hh 也可以换成 kk
dateFormat.setLenient(false);
Date timeDate = dateFormat.parse(dateString); // util类型
Timestamp dateTime = new Timestamp(timeDate.getTime()); // Timestamp类型, timeDate.getTime()返回一个 long 型
System.out.println(dateTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss.SSS",Locale.ENGLISH); // HH 也可以换成 kk
Date dat