Category:DateTimeRecipes
From Erlang Community
| Revision as of 00:08, 4 September 2006 (edit) Bfulgham (Talk | contribs) ← Previous diff |
Current revision (08:51, 4 December 2006) (edit) (undo) Andreas (Talk | contribs) m (Reverted edits by Kaiserpanda (Talk); changed back to last version by Bfulgham) |
||
| (2 intermediate revisions not shown.) | |||
| Line 17: | Line 17: | ||
| Erlang also provides support for date and time manipulation under the Gregorian calendar. The [http://en.wikipedia.org/wiki/Gregorian_Calendar 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. | Erlang also provides support for date and time manipulation under the Gregorian calendar. The [http://en.wikipedia.org/wiki/Gregorian_Calendar 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 | + | 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: | 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: | ||
Current revision
[edit] 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.
Articles in category "DateTimeRecipes"
There are 8 articles in this category.
C |
C cont.DR |
TW |

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

