Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset time part of Calendar instance in Java

There is Java code,which is ran on 2 different environments and inserts records with JdbcTemplate to DB.

Results of its running are different for both envs. Particularly,for Date fields.

On first environment(Oracle XE) it produces record:

"12/03/2010";191094;"71697211000";3229;880323202;NULL;0;1;0;NULL;0;NULL

Second environment(Oracle non XE):

"12/03/2010 12:00:00";191094;"71697211000";3229;880323202;NULL;0;1;0;NULL;0;NULL

NLS_DATE_FORMAT(if it's crucial) for first env is DD-MON-RR, for second env is DD-MON-RRRR

The question is,what Oracle settings may affect,that second env Date format is another?

like image 604
sergionni Avatar asked Dec 06 '10 10:12

sergionni


People also ask

How do I reset the date in Java?

Calendar. clear(field) Reset the value of field to undefined. field : Required Calendar field, Year, month , date, hour , minute , second , millseconds. The method isSet() returns true or false based on the value set for the field or not.

How do I set the time on my calendar object?

Java Calendar setTime() MethodThe setTime () method of java. util. Calendar class is used to set the Time of current calendar object. A Date object id is passed as the parameter into this method.

What is calendar getInstance () in Java?

The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar.

Can you format calendar in Java?

You can format the calender date object when you want to display and keep that as a string.


1 Answers

should set following Calendar properties in Java code:

  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
  cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
  cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
  cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));

instead of:

  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.HOUR_OF_DAY, 0);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);
like image 148
sergionni Avatar answered Oct 05 '22 11:10

sergionni