java convert timestamp to date and time
2014-02-15 16:25
363 查看
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest {
public static void main(String[] args) {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Date date = new Date(timestamp.getTime());
System.out.println(date);
SimpleDateFormat simpleDateFormats = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(simpleDateFormats.format(date));
// S is the millisecond
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
System.out.println(simpleDateFormat.format(timestamp));
System.out.println(simpleDateFormat.format(date));
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest {
public static void main(String[] args) {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Date date = new Date(timestamp.getTime());
System.out.println(date);
SimpleDateFormat simpleDateFormats = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(simpleDateFormats.format(date));
// S is the millisecond
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
System.out.println(simpleDateFormat.format(timestamp));
System.out.println(simpleDateFormat.format(date));
}
}
相关文章推荐
- Simple trick to convert Date format with timezone in Java!
- Java – Convert date and time between timezone
- ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
- Java – Convert date and time between timezone
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill
- Explain differences among java.util.Date, java.sql.Date, java.sql.Time, and java.sql.Timestamp?
- java.util.Date vs java.sql.Date, java.sql.Time and java.sql.Timestamp
- java: long to Date/Time/Timestamp
- Unable to convert MySQL date/time value to System.DateTime
- Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
- java.sql.SQLException: Cannot convert value '2017-07' from column 6 to TIMESTAMP.
- java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和总结 转
- mysql c# Unable to convert MySQL date/time value to System.DateTime 错误
- Unable to convert MySQL date/time value to System.DateTime
- 122. Best Time to Buy and Sell Stock II Java
- Best Time to Buy and Sell Stock leetcode java
- Best Time to Buy and Sell Stock Java
- java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和总结
- 10 ways to format time and date using JavaScript
- Java Date, Calendar and Time API - Tutorial