I have two questions:
How 开发者_Python百科can I get current year (not date) in haskell ?
How can I get quantity days in some month some year ? For example 04.2011 has got 30 days.
This will give you the year, month and day:
import Data.Time.Clock
import Data.Time.Calendar
date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay
Source: http://www.haskell.org/haskellwiki/Date
There's a function in Date.Time.Calendar called gregorianMonthLength with type Integer -> Int -> Int. It takes a year and a month as arguments, returns the number of days, just like you need. http://www.haskell.org/ghc/docs/7.0.2/html/libraries/time-1.2.0.3/Data-Time-Calendar.html
A full example:
import Data.Time.Clock
import Data.Time.Calendar
date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay
main = do
(year, month, day) <- date
putStrLn $ "Days in this month: " ++ (show $ gregorianMonthLength year month)
精彩评论