date - 当前年份和月份中的天数

标签 date haskell time

我有两个问题:

如何在 haskell 中获取当前年份(不是日期)?

如何在某年某月获得数量天数?例如 04.2011 有 30 天。

最佳答案

这将为您提供年、月和日:

import Data.Time.Clock
import Data.Time.Calendar

date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay

来源:http://www.haskell.org/haskellwiki/Date

Date.Time.Calendar 中有一个名为 gregorianMonthLength 的函数,其类型为 Integer -> Int -> Int。
它需要一年和一个月作为参数,返回天数,就像你需要的那样。
http://www.haskell.org/ghc/docs/7.0.2/html/libraries/time-1.2.0.3/Data-Time-Calendar.html

一个完整的例子:
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)

关于date - 当前年份和月份中的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5729570/

相关文章:

Java将String解析为LocalDateTime而不提供时间

scala - 是否有类似 Iteratee 的概念从多个来源提取数据?

python - Python : Alert if more than N errors in a given period? 日志解析

php - 使用可变时区从 PHP 中的 UTC 转换

java - 根据日期比较两条记录并返回cassandra中最新的记录

javascript - 设置日期格式以显示 "Today"/"Tomorrow"而不是 JqxGrid 中的月日

mysql - 在 MySQL 中使用 varchar 而不是日期字段类型

haskell - 方阵的嵌套数据类型

haskell - Haskell 如何立即计算出这个庞大的数字?

python - 将 epoch/unix 时间转换为可读格式