Difference between revisions of "Unix tools/Date"
From HaskellWiki
Tomjaguarpaw (talk | contribs) (Deleting page that hasn't been updated for over 10 years) |
m (Reverted edits by Tomjaguarpaw (talk) to last revision by DonStewart) |
||
Line 1: | Line 1: | ||
+ | Example use of the System.Time library. | ||
+ | <haskell> | ||
+ | -- | ||
+ | -- Implement the unix 'date' command in Haskell | ||
+ | -- | ||
+ | |||
+ | import System.IO | ||
+ | import System.Time | ||
+ | import System.Locale | ||
+ | import System.Environment | ||
+ | |||
+ | main = do | ||
+ | [s] <- getArgs | ||
+ | time <- getClockTime >>= toCalendarTime | ||
+ | putStrLn $ formatCalendarTime defaultTimeLocale s time | ||
+ | </haskell> | ||
+ | |||
+ | Running this code: | ||
+ | |||
+ | <haskell> | ||
+ | $ ghc -O A.hs | ||
+ | |||
+ | $ ./a.out "%a %b %e %H:%M:%S %Z %Y" | ||
+ | Thu Dec 14 12:09:02 EST 2006 | ||
+ | |||
+ | $ ./a.out "%y-%m-%d" | ||
+ | 06-12-14 | ||
+ | </haskell> | ||
+ | |||
+ | [[Category:Code]] | ||
+ | [[Category:Tutorials]] |
Latest revision as of 15:19, 6 February 2021
Example use of the System.Time library.
--
-- Implement the unix 'date' command in Haskell
--
import System.IO
import System.Time
import System.Locale
import System.Environment
main = do
[s] <- getArgs
time <- getClockTime >>= toCalendarTime
putStrLn $ formatCalendarTime defaultTimeLocale s time
Running this code:
$ ghc -O A.hs
$ ./a.out "%a %b %e %H:%M:%S %Z %Y"
Thu Dec 14 12:09:02 EST 2006
$ ./a.out "%y-%m-%d"
06-12-14