943,901 Members | Top Members by Rank

Ad:
Apr 5th, 2007
0

please hlep me in js

Expand Post »
Dear all,

I want to convert this date

from

Sun Apr 1 00:00:00 UTC+0200 2007

to

4/1/2007 00:00:00

:rolleyes:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mohandsa is offline Offline
11 posts
since Oct 2006
Apr 6th, 2007
0

Re: please hlep me in js

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...
Last edited by rgtaylor; Apr 6th, 2007 at 3:54 am. Reason: typo
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: newbie??? Including text files in html
Next Thread in HTML and CSS Forum Timeline: getting layermovement in netscape





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC