How can i convert the date-time which i have defined in java.Long to the format of 'hh:mm:ss, dd/mm/yyyy'. I get the output as Finishing-time = 1527666638657, where Finishing-time is in java.long. How can i convert this into 'hh:mm:ss,dd/mm/yyyy' format. Thank you.
Asked
Active
Viewed 524 times
-5
-
5It sounds like you did exactly *no* research before posting this question. http://idownvotedbecau.se/noresearch/ – f1sh May 30 '18 at 08:00
-
This question has been asked and answered a number of times before. Please use your search engine before asking and find a good answer even faster. – Ole V.V. May 30 '18 at 08:11
1 Answers
1
public String convertTime(long time){
Date date = new Date(time);
Format format = new SimpleDateFormat("HH:mm:ss dd MM yyyy");
return format.format(date);
}

hatched
- 795
- 2
- 9
- 34
-
2While your answer is correct simple code-pastes are discouraged. Add some explanation around it maybe to have a good answer. Also the format you are using is not similar to the one OP asked for. – Ben May 30 '18 at 08:02
-
4Please don’t teach the young ones to use the long outdated and notoriously troublesome `SimpleDateFormat` class. At least not as the first option. And not without any reservation. Today we have so much better in [`java.time`, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/) and its `DateTimeFormatter`. – Ole V.V. May 30 '18 at 08:06
-
@Ben ..updated but i don't think there is a need to explain the code, its already very simple and clear – hatched May 30 '18 at 08:08
-
Thank you all. Thank you for noticing so quick and asking me to search. Sorry i did search. Instead writing a long sentence and down voting, all i ask for help, maybe a link would help which i couldn't find. So i can really be faithful. Thank you @hatched for taking your time and helping out. – user9630935 May 30 '18 at 08:31
-
Welcome to Stack Overflow, @user9630935. When you’ve searched in vain, please give this information in your question. Tell us what you’ve searched for and how the hits were unhelpful. You’ll avoid the downvotes (most of them, at least) and you’ll get help improving your search abilities. And probably even more helpful links than you got here. – Ole V.V. May 30 '18 at 08:49