转换日期在erlang [英] convert date in erlang
问题描述
我有一个函数(命名为测试)返回一个日期
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
so01-Jun-2012应该成为06/2012
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).
正如我所说的功能测试返回一个例子在这个窗体中的日期2012年6月1日
as I say the function test return a date for example in this form "01-Jun-2012"
我应该将此表单转换为另一种形式月/年(as结果我的例子06/2012)
an I should convert this form to another form month/year ( as result to my example 06/2012)
我认为我应该开发一个函数,它作为一个参数,以此形式的日期(日 - 月 - 年)a作为这个函数的结果是这个月份/年的日期
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月2日,2012年4月2日,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
正如我所说的功能 返回这种日期(在测试的代码中,我执行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测试时:解析我有这个错误 **异常错误:未定义的函数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)
推荐答案
p>查看 ec_date in erlware_commons ,这是 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屋!