RE: [OT] Date format
Your best bet is to use the static factory methods in the DateFormat class. ie: Locale locale = getLocale(request); //Use struts Action method to get locale dateTimeFormat = ateFormat.getDateTimeInstance( DateFormat.SHORT,DateFormat.SHORT, locale); dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale); timeFormat = DateFormat.getTimeInstance( DateFormat.SHORT, locale); Its all in the javadocs you know. :-) btw In case you were wondering how the java.util.Date.toString() works, heres its source code: public String toString() { DateFormat formatter = null; if (simpleFormatter != null) { formatter = (DateFormat)simpleFormatter.get(); } if (formatter == null) { /* No cache yet, or cached formatter GC'd */ formatter = new SimpleDateFormat(EEE MMM dd HH:mm:ss zzz , Locale.US); simpleFormatter = new SoftReference(formatter); } synchronized (formatter) { formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(this); } } /btw -Original Message- From: Suresh Addagalla [mailto:[EMAIL PROTECTED]] Sent: Thursday, 16 January 2003 22:56 To: [EMAIL PROTECTED] Subject: Date format Hi, Please excuse me for the off-topic question, I need this urgently, so posting it. How can I get the current date format? (style: DateFormat.SHORT, locale: Default) I used: SimpleDateFormat formatter = new SimpleDateFormat() ; String format = formatter.toPattern() ; It gives: M/d/yy hh:mm a But what I want is *only* the date part, excluding the time part of it. Thanks, Suresh -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: [OT] Date format
Hi, What I am looking for is how to display the *format*, and not how to display a date in a given format. So, there doesn't seem to be anything provided with the API. I need a method like toPattern() of SimpleDateFormat in the DateFormat class because getDateInstance() returns me DateFormat and not SimpleDateFormat. Suresh -Original Message- From: Andrew Hill [mailto:[EMAIL PROTECTED]] Sent: Friday, January 17, 2003 9:11 AM To: Struts Users Mailing List Subject: RE: [OT] Date format Your best bet is to use the static factory methods in the DateFormat class. ie: Locale locale = getLocale(request); //Use struts Action method to get locale dateTimeFormat = ateFormat.getDateTimeInstance( DateFormat.SHORT,DateFormat.SHORT, locale); dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale); timeFormat = DateFormat.getTimeInstance( DateFormat.SHORT, locale); Its all in the javadocs you know. :-) btw In case you were wondering how the java.util.Date.toString() works, heres its source code: public String toString() { DateFormat formatter = null; if (simpleFormatter != null) { formatter = (DateFormat)simpleFormatter.get(); } if (formatter == null) { /* No cache yet, or cached formatter GC'd */ formatter = new SimpleDateFormat(EEE MMM dd HH:mm:ss zzz , Locale.US); simpleFormatter = new SoftReference(formatter); } synchronized (formatter) { formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(this); } } /btw -Original Message- From: Suresh Addagalla [mailto:[EMAIL PROTECTED]] Sent: Thursday, 16 January 2003 22:56 To: [EMAIL PROTECTED] Subject: Date format Hi, Please excuse me for the off-topic question, I need this urgently, so posting it. How can I get the current date format? (style: DateFormat.SHORT, locale: Default) I used: SimpleDateFormat formatter = new SimpleDateFormat() ; String format = formatter.toPattern() ; It gives: M/d/yy hh:mm a But what I want is *only* the date part, excluding the time part of it. Thanks, Suresh **Disclaimer** Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' and 'confidential' and intended for use only by the individual or entity to which it is addressed. You are notified that any use, copying or dissemination of the information contained in the E-MAIL in any manner whatsoever is strictly prohibited. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: [OT] Date format
Ok. This is wierd. I posted this in the morning - now its 11pm and it only just arrived. Maybe I should have used snail mail! Ah of course - its Friday. Guess the email server is taking it easy... ;-) -Original Message- From: Andrew Hill [mailto:[EMAIL PROTECTED]] Sent: Friday, 17 January 2003 11:41 To: Struts Users Mailing List Subject: RE: [OT] Date format Your best bet is to use the static factory methods in the DateFormat class. ie: Locale locale = getLocale(request); //Use struts Action method to get locale dateTimeFormat = ateFormat.getDateTimeInstance( DateFormat.SHORT,DateFormat.SHORT, locale); dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale); timeFormat = DateFormat.getTimeInstance( DateFormat.SHORT, locale); Its all in the javadocs you know. :-) btw In case you were wondering how the java.util.Date.toString() works, heres its source code: public String toString() { DateFormat formatter = null; if (simpleFormatter != null) { formatter = (DateFormat)simpleFormatter.get(); } if (formatter == null) { /* No cache yet, or cached formatter GC'd */ formatter = new SimpleDateFormat(EEE MMM dd HH:mm:ss zzz , Locale.US); simpleFormatter = new SoftReference(formatter); } synchronized (formatter) { formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(this); } } /btw -Original Message- From: Suresh Addagalla [mailto:[EMAIL PROTECTED]] Sent: Thursday, 16 January 2003 22:56 To: [EMAIL PROTECTED] Subject: Date format Hi, Please excuse me for the off-topic question, I need this urgently, so posting it. How can I get the current date format? (style: DateFormat.SHORT, locale: Default) I used: SimpleDateFormat formatter = new SimpleDateFormat() ; String format = formatter.toPattern() ; It gives: M/d/yy hh:mm a But what I want is *only* the date part, excluding the time part of it. Thanks, Suresh -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: [OT] Date format
DateFormat is an abstract class of which SimpleDateFormat is a subclass. When you call getDateInstance() what you get back is actually a SimpleDateFormat - however I am under the distinct impression this depends on the locale. Some locales could in theory give back something different again or if the implementation of the factory methods changes in a future JVM maybe it wouldnt use SimpleDateFormat? You could do an instanceof to check if its a SimpleDateFormat and proceed from there - of course for those locales that dont use SimpleDateFormat then AFAIK you wont be able to get the pattern - this is because pattern is a SimpleDateFormat feature and not a DateFormat thing so if it isnt a SimpleDateFormat (or subclass of SimpleDateFormat) then there isnt a pattern you can make use of anyway! (I could be wrong on that) Out of curiosity I tried the following: Locale[] locales = Locale.getAvailableLocales(); System.out.println(numLocales= + locales.length); for(int i=0; i locales.length; i++) { Locale locale = locales[i]; DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, locale); String klass = df.getClass().getName(); if(!(java.text.SimpleDateFormat.equals(klass))) { System.out.println(class for locale + locale + is + df.getClass().getName() ); } } It reported 145 available locales on my JVM. ALL of them used SimpleDateFormat. (But you cant rely on that - and in general its not considered good practice to make assumptions about which implementation class you get back for a factory method that returns a superclass or interface...) Sorry I cant be of more help :-( -Original Message- From: Suresh Addagalla [mailto:[EMAIL PROTECTED]] Sent: Friday, 17 January 2003 22:42 To: 'Struts Users Mailing List'; [EMAIL PROTECTED] Subject: RE: [OT] Date format Hi, What I am looking for is how to display the *format*, and not how to display a date in a given format. So, there doesn't seem to be anything provided with the API. I need a method like toPattern() of SimpleDateFormat in the DateFormat class because getDateInstance() returns me DateFormat and not SimpleDateFormat. Suresh -Original Message- From: Andrew Hill [mailto:[EMAIL PROTECTED]] Sent: Friday, January 17, 2003 9:11 AM To: Struts Users Mailing List Subject: RE: [OT] Date format Your best bet is to use the static factory methods in the DateFormat class. ie: Locale locale = getLocale(request); //Use struts Action method to get locale dateTimeFormat = ateFormat.getDateTimeInstance( DateFormat.SHORT,DateFormat.SHORT, locale); dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale); timeFormat = DateFormat.getTimeInstance( DateFormat.SHORT, locale); Its all in the javadocs you know. :-) btw In case you were wondering how the java.util.Date.toString() works, heres its source code: public String toString() { DateFormat formatter = null; if (simpleFormatter != null) { formatter = (DateFormat)simpleFormatter.get(); } if (formatter == null) { /* No cache yet, or cached formatter GC'd */ formatter = new SimpleDateFormat(EEE MMM dd HH:mm:ss zzz , Locale.US); simpleFormatter = new SoftReference(formatter); } synchronized (formatter) { formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(this); } } /btw -Original Message- From: Suresh Addagalla [mailto:[EMAIL PROTECTED]] Sent: Thursday, 16 January 2003 22:56 To: [EMAIL PROTECTED] Subject: Date format Hi, Please excuse me for the off-topic question, I need this urgently, so posting it. How can I get the current date format? (style: DateFormat.SHORT, locale: Default) I used: SimpleDateFormat formatter = new SimpleDateFormat() ; String format = formatter.toPatte rn() ; It gives: M/d/yy hh:mm a But what I want is *only* the date part, excluding the time part of it. Thanks, Suresh -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [OT] Date format
RE: [OT] Date formatWith SimpleDateFormat you specify the format as a String. You surely should be able to display that string. What I am looking for is how to display the *format*, and not how to display a date in a given format. (snip)