🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7444

Re: How to parse dates?

#7444
From: Owen Green
Date: Tue, 19 Jun 2001 17:23
34 lines
2120 bytes
> I have a function that returns a date in a month, day, year, time format.
> EG. 10/5/00 7:00:00 AM
>
> What I need to do is only display the date portion of the String only.
> Sometimes the String has a time element some times it does not.
>
> I have been playing around with the DateFormat function but I can't get it
> to work.

Hmm,
If the month / hour had been specified as always taking two digits (i.e. 07
instead of 7)  it would have been easier to predict the lengths of the
strings
in each case and handle accordingly - if they are going to be that variable
then the only option may be to use nested try..catch blocks around attempts
to parse each format, which is quite expensive in terms of overhead
(untested):


{ 
        SimpleDateFormat sdf= new SimpleDateFormat([format specifier1]); 
        return sdf.parse(dateString); 
    }catch(ParseException pe){ 
        try{ 
            SimpleDateFormat sdf = new SimpleDateFormat ([format Specifier 2]); 
            return  sdf.parse(dateString); 
        }catch(ParseException pe){ 
           throw new  MakeUpYourOwnExceptionHere("Un-parseable date"); 
           return null; 
        } 
    } 
    
hth 
Owen
Technical Details
Message-ID: <3b2f8a81$1_1@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!proxad.net!fr.usenet-edu.net!usenet-edu.net!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews
References: <3b2f6a3f$2_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,990109a904f1314
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-19 10:36:23 PST
From: "Owen Green" <owen@norobots.unique.com>
Newsgroups: borland.public.jbuilder.java.language
References: <3b2f6a3f$2_2@dnews>
Subject: Re: How to parse dates?
Date: Tue, 19 Jun 2001 18:23:14 +0100
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 213.86.7.136
Message-ID: <3b2f8a81$1_1@dnews>
X-Trace: dnews 992971393 213.86.7.136 (19 Jun 2001 10:23:13 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!proxad.net!fr.usenet-edu.net!usenet-edu.net!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews