[Haskell-cafe] date parsing and formatting
acowley at seas.upenn.edu
Mon Nov 15 10:33:15 EST 2010
On Sat, Nov 13, 2010 at 4:35 PM, Alex Baranosky
<alexander.baranosky at gmail.com> wrote:
> I've been working with Haskell's Date.Time modules to parse a date
> like 12-4-1999 or 1-31-1999. I tried:
> parseDay :: String -> Day
> parseDay s = readTime defaultTimeLocale "%m%d%Y" s
> And I think it wants my months and days to have exactly two digits instead
> of 1 or 2...
> What's the proper way to do this?
> Also, I'd like to print out my Day in this format: 12/4/1999 what's the
> Haskell way to?
Something like this, perhaps,
parseDate :: String -> LocalTime
parseDate = readTime defaultTimeLocale "%m/%e/%Y"
printDate :: LocalTime -> String
printDate = formatTime defaultTimeLocale "%m/%-e/%Y"
More information about the Haskell-Cafe