What I need to do is:
1) Get user's locale from request.
2) Create new sql.Date object with current date and time, based on user's locale
3) Write it in MySQL db, column type: TIMESTAMP
What I got is:
java.util.Locale locale = request.getLocale();
java.text.DateFormat dateFormat =
java.text.DateFormat.getDateTimeInstance(
java.text.DateFormat.LONG, java.text.DateFormat.LONG, locale );
java.util.Date date = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date( date.getTime() );
Date is OK, but have a problem with time - always 12:00:00 AM.
Any suggestions? Is there a more efficient way to do this?
Even a more compact solution ;)
java.sql.Date timeNow = new Date(Calendar.getInstance().getTimeInMillis());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With