Problem with parse date

I use an algorithm that execute an sql query to an oracle database and return an String [] [] (strObjAuditors[row][col]) array.

when I try to get a date from this array like:

String BirthPlace =  soel.utils.utilities.safeValue(strObjAuditors[row][col]);
the pattern is "yyyy-MM-dd HH:mm:ss.S".

I use the Convert2UtilDate to convert date from String to Date and Convert2StringDate to convert from  Date to String.

until now all working fine on windows xp clients. On linux clients or Windows 7 clients I have problem.
The pattern tha algorithm return is "yyyy-MM-dd HH:mm:ss" the different is ".S".  
I try to change the pattern but I have problem with windows XP clients.

any idea?




public static java.util.Date Convert2UtilDate(String Pattern, String date2covert) {


        java.util.Date utilDate = null;
        if (!safeValue(date2covert).equals("")) {
//            java.text.SimpleDateFormat dateFormatter = (java.text.SimpleDateFormat) java.text.DateFormat.getDateTimeInstance(java.text.SimpleDateFormat.SHORT, java.text.SimpleDateFormat.SHORT, new java.util.Locale("el","GR"));
            java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat(Pattern);
            dateFormatter.setLenient(false);
            dateFormatter.applyPattern(Pattern);
            try {
                utilDate = dateFormatter.parse(date2covert);
            } catch (java.text.ParseException e) {
                e.printStackTrace();
                DialogFinancial("Convert-001. Sf¿¿µa ¿at¿ t¿¿ epe¿e¿¿as¿a¿ t¿¿ ¿µe¿¿µ¿¿¿a¿ " + date2covert + " !", e.toString(), 2, -1);
            }
            return utilDate;
        }
        else {
            return null;
        }
    }

    public static String Convert2StringDate(String Pattern, java.util.Date date2covert) {

        if (date2covert!=null) {
//            java.text.SimpleDateFormat dateFormatter = (java.text.SimpleDateFormat) java.text.DateFormat.getDateTimeInstance(java.text.SimpleDateFormat.SHORT, java.text.SimpleDateFormat.SHORT/*, new java.util.Locale("el","GR")*/);
            java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat(Pattern);
            dateFormatter.setLenient(false);
            dateFormatter.applyPattern(Pattern);

            dateFormatter.applyPattern(Pattern);
            return dateFormatter.format(date2covert);
        }
        else {
            return null;
        }

    }  public static java.util.Date Convert2UtilDate(String Pattern, String date2covert) {


        java.util.Date utilDate = null;
        if (!safeValue(date2covert).equals("")) {
//            java.text.SimpleDateFormat dateFormatter = (java.text.SimpleDateFormat) java.text.DateFormat.getDateTimeInstance(java.text.SimpleDateFormat.SHORT, java.text.SimpleDateFormat.SHORT, new java.util.Locale("el","GR"));
            java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat(Pattern);
            dateFormatter.setLenient(false);
            dateFormatter.applyPattern(Pattern);
            try {
                utilDate = dateFormatter.parse(date2covert);
            } catch (java.text.ParseException e) {
                e.printStackTrace();
                DialogFinancial("Convert-001. Sf¿¿µa ¿at¿ t¿¿ epe¿e¿¿as¿a¿ t¿¿ ¿µe¿¿µ¿¿¿a¿ " + date2covert + " !", e.toString(), 2, -1);
            }
            return utilDate;
        }
        else {
            return null;
        }
    }

    public static String Convert2StringDate(String Pattern, java.util.Date date2covert) {

        if (date2covert!=null) {
//            java.text.SimpleDateFormat dateFormatter = (java.text.SimpleDateFormat) java.text.DateFormat.getDateTimeInstance(java.text.SimpleDateFormat.SHORT, java.text.SimpleDateFormat.SHORT/*, new java.util.Locale("el","GR")*/);
            java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat(Pattern);
            dateFormatter.setLenient(false);
            dateFormatter.applyPattern(Pattern);

            dateFormatter.applyPattern(Pattern);
            return dateFormatter.format(date2covert);
        }
        else {
            return null;
        }

    }

Open in new window

glaAsked:
Who is Participating?
 
Wasim_HaiderConnect With a Mentor Commented:
It seems to be an Oracle timestamp retrieve from database, so you can change your java code. You can use java.sql.Timestamp instead of java.util.Date.
0
 
Wasim_HaiderCommented:
I believe oracle native functions are best to solve this problem. You can use TO_CHAR and TO_DATE when you retrieve data from oracle database.
0
 
glaAuthor Commented:
My algorithm can 't use function to_char() or to_date() only simple SELECT SQL queries. And I need to know about this problem because I have a big java code with embed SQL and is difficult to change. At the five last years all wotking fine, but when we upgrade the workstations to windows 7 and use Linux thin clients I saw this problem with parse date.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Wasim_HaiderCommented:
You need to change your windows date time setting on newly installed windows in where it is not working well. You can see what date format was on your windows workstation previously in where it was working fine.
0
 
glaAuthor Commented:
the "yyyy-MM-dd HH:mm:ss.S" dateformat is special oracle database format (specialy the ".S") is not possible to change via windows 7 workstation.
0
 
Mark GeerlingsDatabase AdministratorCommented:
This looks like a Java problem, not an Oracle problem.  In standard Oracle queries, you would simply use "to_char" and/or "to_date" to convert dates to character strings or characters strings to date values, and you would have complete control over the format mask that you could use.  I'm not a Java expert, but it looks to me like you are counting on Java to do implict data type conversions for you, and for some reason on different O/Ses, the format mask is different.
0
 
gatorvipCommented:
I don't think .S is a valid setting in an Oracle date format. SSSS/SSSSS is the number of seconds after midnight.

Are you sure you're not dealing with an Oracle *timestamp* instead of date?
0
 
glaAuthor Commented:
yes I think, the problem was only on mashines with Linux or Windows 7 OS.
0
All Courses

From novice to tech pro — start learning today.