You should pass the actual Date object to format , not long :
SimpleDateFormat localDateFormat = new SimpleDateFormat("HH:mm:ss"); String time = localDateFormat.format(Utils.getDateObject(DateObject));
Assuming any Utils.getDateObject(DateObject) actually returns Date (which is implied by your question but not really indicated), this should work fine.
For example, this works great:
import java.util.Date; import java.text.SimpleDateFormat; public class SDF { public static final void main(String[] args) { SimpleDateFormat localDateFormat = new SimpleDateFormat("HH:mm:ss"); String time = localDateFormat.format(new Date()); System.out.println(time); } }
Repeat your comment below:
Thanks TJ, but actually I still get 00:00:00 as time.
This means that your Date object has zeros for hours, minutes and seconds, for example:
import java.util.Date; import java.text.SimpleDateFormat; public class SDF { public static final void main(String[] args) { SimpleDateFormat localDateFormat = new SimpleDateFormat("HH:mm:ss"); String time = localDateFormat.format(new Date(2013, 4, 17));
source share