User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 397,813 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,573 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 623 | Replies: 1
Reply
Join Date: Oct 2006
Posts: 8
Reputation: Mohandsa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Mohandsa Mohandsa is offline Offline
Newbie Poster

Help please hlep me in js

  #1  
Apr 5th, 2007
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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: please hlep me in js

  #2  
Apr 6th, 2007
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 2:54 am. Reason: typo
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb HTML and CSS Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the HTML and CSS Forum

All times are GMT -4. The time now is 6:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC