Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of the day from java sql.Timestamp object?

Tags:

java

timestamp

How to get the name of the day from java sql.Timestamp object such as Monday, Tuesday?

like image 471
fatih Avatar asked Nov 08 '10 22:11

fatih


2 Answers

If ts is your Timestamp object then to get the month in string format:

String month = (new SimpleDateFormat("MMMM")).format(ts.getTime()); // "April"

and for the day of the week:

String day = (new SimpleDateFormat("EEEE")).format(ts.getTime()); // "Tuesday"
like image 111
Rocky Inde Avatar answered Nov 14 '22 23:11

Rocky Inde


You convert your java.sql.Timestamp to a java.sql.Date and send it through a Calendar.

java.sql.Timestamp ts = rs.getTimestamp(1);
java.util.GregorianCalendar cal = Calendar.getInstance();
cal.setTime(ts);
System.out.println(cal.get(java.util.Calendar.DAY_OF_WEEK));
like image 42
bwawok Avatar answered Nov 15 '22 00:11

bwawok