I have two questions:
How 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.
To get the number of days in the current month:function getDaysInCurrentMonth() { const date = new Date(); return new Date( date. getFullYear(), date. getMonth() + 1, 0 ). getDate(); } const result = getDaysInCurrentMonth(); console.
The cal_days_in_month() function returns the number of days in a month for a specified year and calendar.
JavaScript getDate() Method: This method returns the number of days in a month (from 1 to 31) for the defined date. Return value: It returns a number, from 1 to 31, representing the day of the month.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With