2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by rgtaylor
0

You say in the title js... if you mean Javascript, then you should post in the Javascritp lists, you'll get better results... If it is a typo and you meant JSP, then I will see what I can do...

However, the priciple is basically the same...
You can build a new date object from the ISO standard string format then use that date object with a date format object to output the date anyway you like...

Do a quick search for SimpleDateFormat on google and you will find pretty much everything you need...

Sorry, but there is too much to detail here...

If it is Javascript you are looking at, you can certainly do it similarly...

If the date is coming from a database, see what you can do for the formating prior to extracting the date, this is DB dependant so I can't give you specifics there, but for example, I use PostgreSQL 8.2 in many of my applications and I usually store timestamp with timezone... Then I can select it as a date which outputs as 4/1/2007 or similar...


If the dates are instrings you can always build a parser routine in js or java to do the work if you like...
String sMyDate = "Sun Apr 1 00:00:00 UTC+200 2007";
String[] aDateParts = sMyDate.split(" ");//the empty space
HashMap<String, Integer> hm = new HashMap(12);
hm.put("Apr", 4); // just a simple mapping
String sDisplayDate = hm.get(aDateParts[1]) + "/" + aDateParts[2] + "/" + aDateParts[5] + " " + aDateParts[3];


That is about it if you are doing string manipulation, which in some cases is faster than creating a date from a string, reformating it using date formatter then outputting it as a date again...

If you have any questions feel free to contact me... The string manipulation method will work in Javascript too, with almost the same code...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.