e r l a n g : c o o k b o o k

/ Erlang.TimeIntroduction

This Web


WebHome 
WebChanges 
TOC
NewRecipe 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Erlang Links


Erlang.org
Erlang Wiki
ErlMan
Erlang Wiki
The Jungerl
Erlang-fr.org
Joe Armstrong
Lambda the Ultimate

Erlang Web Ring


[Prev]: Joe Armstrong's Page
[Next]: Joe Armstrong's Page

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.

Based on work by FranciscoSolsona.

-- BrentAFulgham - 27 Aug 2004

CookbookForm
TopicType: Section
ParentTopic: TimeChapter
TopicOrder: 010

 
 
Copyright © 2004 by the contributing authors. All material on the Erlang Cookbook web site is the property of the contributing authors.
This material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest