You are going to need a calendar. That timestamp is implicitly for the time zone UTC and you will want the time in your local time zone, not to mention handling things like daylight savings time correctly. Use Calendar.
What you are going to do depends on what int values you want for the separate date and time components. For example you might want the int 20060508 for the date component and the int 110138 for the time component. Or you might want something completely different.
long timestampInMillis = 1000L * timeinseconds // has time in seconds from Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timestampInMillis); GregorianCalendar grecal = new GregorianCalendar(cal.YEAR, cal.MONTH, cal.DAY_OF_MONTH); Date dt = grecal.getTime(); int dateComp =(int) dt.getTime()/1000; // has the date component int timeComp = sch.values - dateComp; // has the hr:min:sec component
Looking at your code, I see *two* calendars (cal and grecal) and one big mistake: static constants YEAR, MONTH and DAY_OF_MONTH do not give you cal's year, month and date -- after all they are class constants! (One of the basic rules of Java style states that you never to access class constants in this way. Most IDES will warn you about this, too.) Try redoing this code with one calendar and try using the set method to reset the hour of day, minute, seconds and milliseconds to 0. That will wind the clock back to midnight.
Your code looks okay, but your timestamp for 2038-01-01 is for UTC. Here my code adjusts the Calendar and DateFormat to work in that time zone. You can choose any time zone you like, including your JVM's default: