Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the toString() method in java.util.Date locale independent?

    try {
         SimpleDateFormat strTemp = new SimpleDateFormat("ddMMMyy", Locale.US);
          Date reasult = strTemp.parse(input);
         String   checkDate = reasult.toString().substring(8, 10) + reasult.toString().substring(4, 7) + reasult.toString().substring(26);
         if (!checkDate.toUpperCase().equals(input))
             return false;

         else
          return true;
       } catch (Exception ex) {
            return false;
     }

As the API tells me java.util.Date.toString() is like format "dow mon dd hh:mm:ss zzz yyyy", I just want to know if the content format of toString() will be change while the windows locale changed? Such as "Russian","English", suggest the input is same, the checkDate value is same? Thanks for you help.

like image 865
Sstx Avatar asked Dec 02 '25 10:12

Sstx


1 Answers

Date.toString() is locale independent. The most significant change that you can ever observe is the timezone, which depends on the timezone settings of your computer. This is by design.

Converts this Date object to a String of the form:

   dow mon dd hh:mm:ss zzz yyyy

where:

  • dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
  • mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
  • dd is the day of the month (01 through 31), as two decimal digits.
  • hh is the hour of the day (00 through 23), as two decimal digits.
  • mm is the minute within the hour (00 through 59), as two decimal digits.
  • ss is the second within the minute (00 through 61, as two decimal digits.
  • zzz is the time zone (and may reflect daylight saving time). Standard time zone abbreviations include those recognized by the method parse. If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.
  • yyyy is the year, as four decimal digits.
like image 170
nhahtdh Avatar answered Dec 05 '25 01:12

nhahtdh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!