How can I convert time in unix timestamp to normal time?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your question is vague and ambiguous. I’ll leave the timezone ambiguity away.
I suspect that you’re somehow obtaining a
longor maybe aStringvalue from the DB instead of aDate. In JDBC, you would normally like to use the appropriate methods to obtain the DB-specific datatypes. The MySQLTIMESTAMPdatatype can be obtained byResultSet#getTimestamp()which gives you ajava.sql.Timestampwhich in turn is a subclass ofjava.util.Date.In a nut, the following should do:
To format it further in a human readable format whenever you’re going to present it to the enduser, use
SimpleDateFormat. Click the link, it contains an overview of all patterns. Here’s an example:To do all the other way round, use respectively
SimpleDateFormat#parse()andPreparedStatement#setTimestamp().