INTER.TTS
A Time variable should not be followed by 'toString()' in an Internationalized environment
Description
This rule flags code where a Time variable is followed by `toString()'
If code contains a Time variable followed by a `toString()', it will not run in an internationalized environment because time formats differ with region and language.
Example
package INTER;
import java.sql.*;
import java.awt.*;
public class TTS(){
public void displaytime() {
Time t1= new Time(1000);
String timeString= t1.toString(); //violation
System.out.println(timeString);
}
}
Repair
If you use the date-formatting classes, your application can display dates and time correctly around the world. First, you create a formatter with the
getTimeInstance method as follows:
DateFormat timeFormatter = DateFormat.getTimeInstance(
DateFormat.DEFAULT, currentLocale);
Second, you invoke the format method, which returns a String containing the formatted date/time as follows:
Time t1 = new Time(1000):
String timeString= timeFormatter.format(t1);
Reference
http://java.sun.com/docs/books/tutorial/i18n/intro/checklist.html
http://java.sun.com/docs/books/tutorial/i18n/format/dateFormat.html
|