[erlang-questions] timestamp conversion

Juan Jose Comellas juanjo@REDACTED
Sat Apr 16 00:47:56 CEST 2011

This function should help you convert a string timestamp into the
elapsed seconds since January 1, year 0:

timestamp_to_gregorian_seconds(Timestamp) ->
    %% Divide the string into its different datetime components
    Tokens = string:tokens(Timestamp, "-T:Z"),
    %% Convert each string into an integer
    [Year, Month, Day, Hour, Min, Sec] = [list_to_integer(N) || N <- Tokens],
    %% Convert the datetime to seconds
    calendar:datetime_to_gregorian_seconds({{Year, Month, Day}, {Hour,
Min, Sec}}).

I haven't even compiled it, but it should give you and idea of how to
convert the timestamps.


On Fri, Apr 15, 2011 at 7:13 PM, Peter W. Morreale <pmorreale@REDACTED> wrote:
> This may be embarrassingly simple, but I am struggling with it...
> I need compare string timestamps for dealing with expiration.   In some
> cases it may another string timestamp, in others it will be against the
> current time.
> The string timestamps will always have the format:
> Year-Month-DayTHour:Min:SecZ"
> I think I want to convert to integer seconds, however even then its not
> clear to me how to perform the comparison, although I think this is a
> case for using the "if" expression.
> Please be gentle, I'm still new to Erlang.
> Thanks much
> -PWM
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list