/**
* String --> Date
*/
@SuppressWarnings("deprecation")
public static void stringToDate(){
String dateStr = "2013/10/18 14:25:33";
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
date = df.parse(dateStr);
System.out.println(date.toLocaleString());
} catch (ParseException e) {
e.printStackTrace();
}
}
/**
*
* Date --> String
*
*/
public static void dateToString(){
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(sdf.format(date));
System.out.println(sdf1.format(date));
}
/**
* Timestamp --> String
*/
public static void timestampToString(){
Timestamp ts = new Timestamp(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(ts));
System.out.println(ts.toString());
}
/**
* 测试Timestamp 的valueOf()
*/
public static void timeStampValueOf(){
Timestamp ts = new Timestamp(System.currentTimeMillis());
String tsStr = "2013-10-18 14:57:28";
ts = Timestamp.valueOf(tsStr);
System.out.println(ts);
}
/**
* Timestamp --> Date
*/
public static void TimestampToDate(){
Timestamp ts = new Timestamp(System.currentTimeMillis());
Date date = new Date();
System.out.println(ts);
System.out.println(date);
date = ts;
System.out.println(date);
}
/**
* Date --> Timestamp
*
* Date 和 Timestamp 是父子类关系 所以Date不能直接想Timestamp转换
*/
public static void dateToTimestamp(){
Timestamp ts = new Timestamp(new Date().getTime());
System.out.println(ts);
}
* String --> Date
*/
@SuppressWarnings("deprecation")
public static void stringToDate(){
String dateStr = "2013/10/18 14:25:33";
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
date = df.parse(dateStr);
System.out.println(date.toLocaleString());
} catch (ParseException e) {
e.printStackTrace();
}
}
/**
*
* Date --> String
*
*/
public static void dateToString(){
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(sdf.format(date));
System.out.println(sdf1.format(date));
}
/**
* Timestamp --> String
*/
public static void timestampToString(){
Timestamp ts = new Timestamp(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(ts));
System.out.println(ts.toString());
}
/**
* 测试Timestamp 的valueOf()
*/
public static void timeStampValueOf(){
Timestamp ts = new Timestamp(System.currentTimeMillis());
String tsStr = "2013-10-18 14:57:28";
ts = Timestamp.valueOf(tsStr);
System.out.println(ts);
}
/**
* Timestamp --> Date
*/
public static void TimestampToDate(){
Timestamp ts = new Timestamp(System.currentTimeMillis());
Date date = new Date();
System.out.println(ts);
System.out.println(date);
date = ts;
System.out.println(date);
}
/**
* Date --> Timestamp
*
* Date 和 Timestamp 是父子类关系 所以Date不能直接想Timestamp转换
*/
public static void dateToTimestamp(){
Timestamp ts = new Timestamp(new Date().getTime());
System.out.println(ts);
}