|
| |||||||||
| Tags: date, format, java, java tools, javautil, programming language, utilities |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Problem in date format
Hello, I need to format dates depending on the locale. These dates must be in digital format. DateFormat that almost meets my needs: Code: DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); |
|
#2
| |||
| |||
| Re: Problem in date format
Hello, I do not know what format DateFormat.short but you can SimpleDateFormat formatter as you like: For example: Code: Code: SimpleDateFormat s = new SimpleDateFormat("YYYYMMDD");
System.out.System.out.println(s.format(new Date())); |
|
#3
| |||
| |||
| Re: Problem in date format
Hello, Your solution is good but I do not think this is what will help him, because you lose all the information moves on the local ... It will display the date in short format according to the usual local user, ie: * dd / MM / yy for en_US MM-dd-yy for en_US etc. ... This is possible through the method DateFormat.getDateInstance () |
|
#4
| |||
| |||
| Re: Problem in date format
Hello, One solution would be to change the pattern returned ... It seems that it is therefore an object SimpleDateFormat the following code should do the trick: Code: DateFormat dtfr = DateFormat.getDateInstance(DateFormat.SHORT);
if (dtfr instanceof SimpleDateFormat) {
SimpleDateFormat sdtfr = (SimpleDateFormat) dtfr;
String ptr = sdtfr.toLocalizedPattern();
if (ptr.indexOf(yyyy)==-1) {
dtfr = new SimpleDateFormat(ptr.replaceFirst("yy", yyyy));
}
} Otherwise we create a new SimpleDateFormat with 4-digit year if it is not the case. |
|
#5
| |||
| |||
| Re: Problem in date format
Hello, I have this temporary solution to almost exactly: Instead of: Code: if (ptr.indexOf(yyyy)==-1) {
df = new SimpleDateFormat(ptr.replaceFirst("yy", yyyy));
} Code: df = new SimpleDateFormat(pattern.replaceFirst("y +", yyyy)); |
|
#6
| |||
| |||
| Re: Problem in date format
Hello, Actually re-reading the post it is specified and said: "depending on the locale," I therefore advise every beginner in java to be sure to read before going to Java and especially before trying to do some example, I feel so because every programmer should have the basic knowledge strong , that it the basics of the language should be strong. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Problem in date format" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using date format in JSP | KAMANA | Software Development | 6 | 29-07-2010 11:32 AM |
| Format Date and Time Script in ASP | Beter 2 Burn Out | Software Development | 4 | 10-02-2010 02:22 AM |
| Insert date format in SQL via ASP | Bansi_WADIA | Software Development | 4 | 04-12-2009 10:56 PM |
| Changing the date format | Uzair | Customize Desktop | 3 | 03-04-2009 01:44 PM |
| whenCreated Date Format | Seagull Ng | Active Directory | 3 | 04-01-2007 08:44 AM |