Erlang Central

Category:DateTimeRecipes

Revision as of 04:32, 4 December 2006 by RJ (Talk | contribs)

Introduction

Erlang provides basic, but important ways of manipulating time and dates. erlang:localtime built-in function returns the current time as a tuple of tuples:

{{Year,Month,Day},{Hour,Min,Seconds}}.

The erlang:now built-in function returns the current time as a tuple:

{MegaSecs,Secs,Microsecs}.

These tuples are based on a platform-specific starting date, or epoch.

Erlang also provides support for date and time manipulation under the Gregorian calendar. The Gregorian calendar in this module is extended back to year 0. For a given date, the gregorian days is the number of days up to and including the date specified. Similarly, the gregorian seconds for a given date and time, is the the number of seconds up to and including the specified date and time.

The value of erlang:now increases as time passes (increasing by 1 for each second that passes). Since people are not used to working with seconds (or MegaSeconds for that matter), Erlang provides several convenience functions to convert now formatted time to date-time values: now_to_local_time, which returns the local date and time converted from the return value from erlang:now; now_to_universal_time, which returns UTC time for an erlang:now value; and the now_to_datetime function, which returns a DateTime formatted value.

Erlang also provides a variety of helpful date-specific functions. For example, the built-in-function date provides the current date. So, for instance printing the current year is as simple as:

1> {Year,_,_} = erlang:date().
{2004,8,27}
2> Year.
2004

We will discuss these and other calendar functions in the following recipes.


casinos strategy online casino games strategy casinos online casino on the net on line roulette game Gambling Online - Risks. casinos strategy online casino directory Casino Games and variations. casino games game