This question already has answers here:
How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?
(16 answers)
Closed 6 years ago.
On my DB i have a date column with this format: '2016-10-05'
How can i obtain the actual date on this format?
I tried with
Date date = new Date();
But the format is not compatible and it doesen't works.
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(stringWithDate);
You have to use SimpleDataFormat which allows you to parse Strings with different formats to Date
Related
This question already has answers here:
How do I convert the date from one format to another date object in another format without using any deprecated classes?
(10 answers)
Closed 4 years ago.
How do I convert date format from
dd-mm-yyyy
to
YYMMDD
in java?
I think you are seeking the solution like date formatting. You can try to use DateTimeFormatter with your own pattern.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy-MM-dd");
This question already has answers here:
Convert unix timestamp to date in java [duplicate]
(3 answers)
Closed 5 years ago.
I receive date and time from openweather api in such format "dt":1489602000", I don't know what that mean. I want to receive something like this "2014-07-23 09:00:00" How can I transform it using SimpleDateFormat
String transformedDate = new SimpleDateFormat("H:mm dd MMM yy").format(new Date(yourTime*1000));
Customize your date format like there
This question already has answers here:
java.util.Date format conversion yyyy-mm-dd to mm-dd-yyyy
(8 answers)
Closed 7 years ago.
Has java any function where I have a String with a date in this form : ddMMyy or dd.MM.yy
and I want to convert it in another format like: dd:MM:yy
I would suggest using two SimpleDateFormat objects for this.
Date date = new SimpleDateFormat("ddMMyy").parse( dateString);
String result = new SimpleDateFormat("dd:MM:yy").format( date );
For the format, see the documentation: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
This question already has answers here:
How to format a date String into desirable Date format
(5 answers)
Closed 7 years ago.
I desire to format date string ex.Jul1,201512: 00: 00AM to date in format 'dd/MM/yyyy'.
If any one knows is please share the solution with me
Use a SimpleDateFormat to parse your original string and then another one to format it into the desired format.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Parse any date in Java
Suppose we have a string of date in a format (unknown to the user). Examples of acceptable dates that you can receive from a user:
yyyy-MM-dd/yy-MM-dd
yyyy/MM/dd/yy/MM/dd
dd/MM/yyyy/dd/MM/yy
MM/dd/yyyy/MM/dd/yy`
Is there a library that accept a date in a string and returns a date format that can be used by SimpleDateFormat or Joda Time?
Thanks
As a simple solution: I will apply each date format on the provided input to get a Date object , then I print the Date object with the same date format. If the input and the output for a date format are the same the date format is a candidate.