Need help with date format in java?
-
Date currentDateFormat() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); //get current date time with Date() Date date = new Date(); Date d = dateFormat.format(date); return d; } I am trying to store the value of d in a table, the column is of type Date. I am getting this Error, Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types required: java.util.Date found: java.lang.String at database_entry.MyMethods.currentDateForm… at database_entry.DBEntry.main(DBEntry.java… I do understand that dateFormat.format(date) is a string and should be stored in a string. However, I need to have the same format for a type Date in order for me to be able to store it into the database. If I only use date = new Date(); it does give me the date but in this format, Tue Apr 10 12:22:01 AST 2012 Any ideas?
-
Answer:
If I only use date = new Date(); it does give me the date but in this format, Tue Apr 10 12:22:01 AST 2012 The above statement is wrong! A data type of Date stores a number. The number of days offset from a base date (possibly 01/01/1970). What you are seeing when you display a date is the system standard format. Change the standard format and your problem is fixed. You do not have to change the Date on the database. Only the format. Have fun.
Bleh22 at Yahoo! Answers Visit the source
Related Q & A:
- How to Convert Json date string to more readable date format?Best solution by SharePoint
- How to change the date format yyyy/mm/dd to dd/mm/yyyy in below code?Best solution by scn.sap.com
- How to change date format using jquery?Best solution by Stack Overflow
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- I need help with writing up the Java Code.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.