Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Why Java Date displaying date as 'Sat Sep 05 00:00:00 IST 2020' when I give format as 'Sep 05, 2020'

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My intension is to get the earliest date in a list and I wrote code like this



I am getting Min Date as Sat Sep 05 00:00:00 IST 2020 which is not the format I gave ! How would I tackle this ?
 
Marshal
Posts: 25968
70
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Meg Maliyam wrote:I am getting Min Date as Sat Sep 05 00:00:00 IST 2020 which is not the format I gave ! How would I tackle this ?



You didn't give any format at all. You just output the date. (Hint: You created that date by parsing it from a String using some format, but that's a different thing entirely.)

There's a way of formatting a Date to a String; use that and then output the formatted String.
 
Marshal
Posts: 70718
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If at all possible, stop using Date and Calendar. Go through the Java™ Tutorials, and use one of the classes described there.
 
Saloon Keeper
Posts: 7395
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read your code it made me think of the parse/format scenarios I've run into before where it would have been handy to have the formatting follow the date object so that it knows how to format itself. I dashed out this demo to see what it might look like. Of course Campbell is right about moving away from the Date class.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic