如何在Erlang中的日期格式之间转换? [英] How to convert between date formats in Erlang?
问题描述
我有一个返回日期的函数(名为 test )
I have a function ( named test) which return a date
我为您提供这种返回示例: 2012年6月1日
I give you an example of this kind of return : "01-Jun-2012"
现在我要以这种形式将日期设置为月/年
Now I want to make this date in this form month/year
因此 2012年6月1日应变为 2012年6月6日
so "01-Jun-2012" should became "06/2012"
因为我想将此日期用于发送短信
because I want to use this Date to send sms
send(To,Date) ->
Message =io_lib_format("pr%EAt %E0 payer le ~s",[Date]),
Url = io_lib:format("http://192.168.1.8/sendsms?tel=~s&text=~s", [To, Message]),
http:request(lists:flatten(Url), sms).
我说函数 test 以这种形式返回日期 2012年6月1日
as I say the function test return a date for example in this form "01-Jun-2012"
我应该将此表单转换为另一种月/年(我的示例结果为06/2012)
an I should convert this form to another form month/year ( as result to my example 06/2012)
我认为我应该开发一个函数,该函数应将以下形式的Date作为参数(日-月-年)和该函数的结果为月/年格式的日期
I think I should develop a function which has as a parameter a Date in this form ( day-month-year) an as a result for this function a date in this form month/year
请注意,我给您同样的日期示例,应将其转换为:02-Jan-2012,01-Feb -2012、2012年3月1日,2012年4月2日,2012年5月1日,2012年6月1日
note, I give you same example of date which should be convert : 02-Jan-2012 , 01-Feb-2012 ,01-Mar-2012 ,02-Apr-2012 , 01-May-2012 , 01-Jun-2012
我说的是功能 test 返回这种日期(在 test 的代码中,我执行http请求是为了返回这种日期日-月-年(是php脚本的返回,
as I say the function test return this kind of date ( in the code of test I execute http request in order to return this kind of date day-month-year ( is a return of php script,
谢谢,但是当我用ec_date:parse测试时,出现此错误 **异常错误:未定义函数ec_date:parse / 1
thanks , but when I test with ec_date:parse I have this error ** exception error: undefined function ec_date:parse/1
请注意,我使用的是erlang版本13
note , that I work with version 13 of erlang
Erlang R13B03 (erts-5.7.4) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.7.4 (abort with ^G)
推荐答案
在erlware_commons中查看 ec_date ,它是 dh_date 。 (两者都是完全有效的,但是我个人使用ec_date变体)/
Look into ec_date in erlware_commons, which is a fork of dh_date. (Both are perfectly valid, but I personally use the ec_date variant)/
它们都可以完全用于此目的:解析和格式化日期。
They both can be used for exactly this purpose: parsing and formatting dates.
> OrigDate = "01-Jun-2012",
> ParsedDate = ec_date:parse(OrigDate),
> FinalDate = ec_date:format("m/Y",ParsedDate).
"06/2012"
这篇关于如何在Erlang中的日期格式之间转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!