From e05f92d7641036bebbec8c809c59860482ec1184 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 22 Apr 2019 16:51:22 -0700 Subject: [PATCH] PE: Starting ch4 exercises. --- pe/chapter4.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pe/chapter4.erl b/pe/chapter4.erl index 6f7730a..fe64ead 100644 --- a/pe/chapter4.erl +++ b/pe/chapter4.erl @@ -1,5 +1,5 @@ -module(chapter4). --export([t2l/1, timeit/1]). +-export([t2l/1, timeit/1, date_string/0]). % 2. The BIF tuple_to_list(T) converts the elements of the tuple T to % a list. Write a function called my_tuple_to_list(T) that does the % same thing only not using the BIF that does this. @@ -25,6 +25,12 @@ timeit(F) -> F(), {erlang:system_time(microsecond) - Started, microsecond}. +date_string() -> + {Hour, Minute, Second} = erlang:time(), + {Year, Month, Day} = erlang:date(), + io:format("~w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", + [Year, Month, Day, Hour, Minute, Second]). + % 4. Advanced: Look up the manual pages for the Python datetime % module. Find out how many of methods in the Python datetime class % can be implemented using the time-related BIFs in the erlang