Dates are classified as Big-endian, Little-endian and Middle-endian.
Big-Endian meaning Most significant to Least significant, ie Year->Month->Day
Little-Endian meaning Least significant to Most significant, ie Day->Month->Year
Middle-Endian means it is neither of the above, ie it is Month->Day->Year.
We can see
International Standard ISO 8601 notation follows Big-Endian format (YYYY/MM/DD)
British date notation follows Little-Endian format.(DD/MM/YY)
American date notation follows Middle-Endian format.(MM/DD/YY).
Among the above formats (using only numbers).
USA and UK notations can cause confusion, but not ISO 8601 format.
For instance
The date 02/03/16 can indicate two different dates.
UK notation (Little-Endian) means, it is 2nd of March in the year 2016.
USA notation (Middle-Endian) means, it is 3rd of February in the Year 2016.
But using numbers has advantages.
It is language independent, easy to read, enter and manipulate.
International Standard ISO 8601 notation is most suitable for this purpose.
Its noattion being YYYY-MM-DD.
It can't be misread even if we remove the separators(YYYYMMDD).
Having said that,
there are other factors which would decide the final format.
This simple program uses an array to store the above date formats and
displays the system date in each format through a 'for' loop with description.
/* RESOURCES required
import java.util.Date; // For date object with current date and time
import java.text.SimpleDateFormat; // to apply user format
public class GetDateTime {
public static void main(String[] args) {
/* Arrays to store date formats and their description
Note: Formats are case sensitive- (Eg)'M' for month, 'm' for minutes */
String[] DateFts = { "YYYY/MM/dd",
"MM.dd.yy",
"dd/MM/yy"};
String[] DateFtsDes = { "ISO 8601 notation (Big",
" USA notation (Middle",
" UK notation (Little"};
// date object 'dateobj' with current date
Date dateobj = new Date();
//'df' as SimpleDateformat object
SimpleDateFormat df;
int i;
// Displaying date without formatting
System.out.println( "Unformatted Current date with time: " + dateobj);
System.out.println( "Formated date with SimpleDateFormat(): ");
// loop to display date in the formats stored in the Array
for (i=0;i<DateFts.length;++i){
df = new SimpleDateFormat(DateFts[i]); //Initializing 'df' through iteration
System.out.println( (i+1) + ") " // Array Index starts with 0,so i+1
+" Format : " + "SimpleDateFormat("
+ DateFts[i] + ")" // To display Format text
+ "\n" + " Output : "
+ df.format(dateobj) + " " //Formating the Date
+"\n" +" Description :"
+ DateFtsDes[i] // To display description
+ "-Endian)");
}
}
}
Output of the Program:
Unformatted Current date with time: Thu Feb 18 16:08:22 IST 2016
Formated date with SimpleDateFormat():
1) Format : SimpleDateFormat(YYYY/MM/dd)
Output : 2016/02/18
Description :ISO 8601 notation (Big-Endian)
2) Format : SimpleDateFormat(MM.dd.yy)
Output : 02.18.16
Description : USA notation (Middle-Endian)
3) Format : SimpleDateFormat(dd/MM/yy)
Output : 18/02/16
Description : UK notation (Little-Endian)
No comments:
Post a Comment