<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Time_and_Date</id>
		<title>Time and Date - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Time_and_Date"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Time_and_Date&amp;action=history"/>
		<updated>2026-04-18T21:26:56Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Time_and_Date&amp;diff=278&amp;oldid=prev</id>
		<title>Harald: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Time_and_Date&amp;diff=278&amp;oldid=prev"/>
				<updated>2016-10-27T16:03:01Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 16:03, 27 October 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Time_and_Date&amp;diff=277&amp;oldid=prev</id>
		<title>Harald: /* See also */</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Time_and_Date&amp;diff=277&amp;oldid=prev"/>
				<updated>2012-10-12T14:30:48Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;See also&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Test Environments ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;smalldiv&amp;quot;&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; |&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | Hardware Comments&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.6.3'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.6.4'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.7.4'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.0'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.7'''&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;Ethernut 1.3 H&amp;lt;/span&amp;gt;&lt;br /&gt;
| No RTC hardware.&amp;lt;br&amp;gt;Date and time settings are lost after reset.&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut13H-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut13H-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut13H-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Time-and-date-enut13H-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;Ethernut 2.1 B&amp;lt;/span&amp;gt;&lt;br /&gt;
| No RTC hardware.&amp;lt;br&amp;gt;Date and time settings are lost after reset.&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut21B-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut21B-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut21B-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Time-and-date-enut21B-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' AVR-GCC 4.3.2&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 3.0 E&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| OK&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut30E-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut30E-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-enut30E-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [[Media:Time-and-date-enut30E-nutos-4.8.7.zip|'''Binaries''']]&amp;lt;br&amp;gt;'''Compiler:''' ARM-GCC 4.3.3&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;EIR 1.0&amp;lt;/span&amp;gt;&lt;br /&gt;
| Set jumper JP1 to UART mode.&lt;br /&gt;
| OK&amp;lt;br&amp;gt;&lt;br /&gt;
Add&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
outr(PIOA_PDR, _BV(PA5_RXD0_A) | _BV(PA6_TXD0_A));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
immediately after NutRegisterDevice().&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-EIR1C-nutos-4.6.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-EIR1C-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/time-and-date-EIR1C-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
|&lt;br /&gt;
|- &lt;br /&gt;
| id=&amp;quot;compilertd&amp;quot; colspan=&amp;quot;5&amp;quot; |'''Compiler:''' ARM-GCC 4.2.2 ; AVR-GCC 4.3.0&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
This is an example on how to build a simple clock with Nut/OS.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;dev/board.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dev/debug.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/timer.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;io.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;time.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static char *weekday_name[7] = {&lt;br /&gt;
    &amp;quot;Sunday&amp;quot;, &amp;quot;Monday&amp;quot;, &amp;quot;Tuesday&amp;quot;, &amp;quot;Wednesday&amp;quot;, &amp;quot;Thursday&amp;quot;, &amp;quot;Friday&amp;quot;, &amp;quot;Saturday&amp;quot;};&lt;br /&gt;
static char *month_name[12] = {&lt;br /&gt;
    &amp;quot;January&amp;quot;, &amp;quot;February&amp;quot;, &amp;quot;March&amp;quot;, &amp;quot;April&amp;quot;, &amp;quot;May&amp;quot;, &amp;quot;June&amp;quot;, &amp;quot;July&amp;quot;, &amp;quot;August&amp;quot;,&lt;br /&gt;
    &amp;quot;September&amp;quot;, &amp;quot;October&amp;quot;, &amp;quot;November&amp;quot;, &amp;quot;December&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
static void PrintDateTime(CONST struct _tm *stm)&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%s, %02d. %s %04d, %02d:%02d:%02d&amp;quot;, weekday_name[stm-&amp;gt;tm_wday],&lt;br /&gt;
        stm-&amp;gt;tm_mday, month_name[stm-&amp;gt;tm_mon], stm-&amp;gt;tm_year + 1900,&lt;br /&gt;
        stm-&amp;gt;tm_hour, stm-&amp;gt;tm_min, stm-&amp;gt;tm_sec);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void DisplayLocalTime(void)&lt;br /&gt;
{&lt;br /&gt;
    time_t tt;&lt;br /&gt;
    struct _tm *ltm;&lt;br /&gt;
&lt;br /&gt;
    while (!kbhit()) {&lt;br /&gt;
        tt = time(NULL);&lt;br /&gt;
        ltm = localtime(&amp;amp;tt);&lt;br /&gt;
        PrintDateTime(ltm);&lt;br /&gt;
        printf(&amp;quot;\r&amp;quot;);&lt;br /&gt;
        NutSleep(100);&lt;br /&gt;
    }&lt;br /&gt;
    putchar('\n');&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    u_long baud = 115200;&lt;br /&gt;
    NutRegisterDevice(&amp;amp;DEV_UART, 0, 0);&lt;br /&gt;
    freopen(DEV_UART_NAME, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
    freopen(DEV_UART_NAME, &amp;quot;r&amp;quot;, stdin);&lt;br /&gt;
    _ioctl(_fileno(stdout), UART_SETSPEED, &amp;amp;baud);&lt;br /&gt;
&lt;br /&gt;
#ifdef RTC_CHIP&lt;br /&gt;
    NutRegisterRtc(&amp;amp;RTC_CHIP);&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
    DisplayLocalTime();&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output ==&lt;br /&gt;
&lt;br /&gt;
 Wednesday, 31. December 1969, 19:00:00&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
&lt;br /&gt;
The first 9 lines include the required libraries for this program, as usual.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;static char *weekday_name[7] = {&amp;quot;Sunday&amp;quot;, &amp;quot;Monday&amp;quot;, &amp;quot;Tuesday&amp;quot;, &amp;quot;Wednesday&amp;quot;, &amp;quot;Thursday&amp;quot;, &amp;quot;Friday&amp;quot;, &amp;quot;Saturday&amp;quot;};&amp;lt;/source&amp;gt;&lt;br /&gt;
declares an array of 7 pointers (of type char) and calls the array &amp;lt;code&amp;gt;weekday_name&amp;lt;/code&amp;gt;.&lt;br /&gt;
Each of those pointers point to an adress in memory where the specified strings are stored (e.g. &amp;quot;Sunday&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;static char *month_name[12] = {&lt;br /&gt;
    &amp;quot;January&amp;quot;, &amp;quot;February&amp;quot;, &amp;quot;March&amp;quot;, &amp;quot;April&amp;quot;, &amp;quot;May&amp;quot;, &amp;quot;June&amp;quot;, &amp;quot;July&amp;quot;, &amp;quot;August&amp;quot;,&lt;br /&gt;
    &amp;quot;September&amp;quot;, &amp;quot;October&amp;quot;, &amp;quot;November&amp;quot;, &amp;quot;December&amp;quot;};&lt;br /&gt;
&amp;lt;/source&amp;gt;behaves analog.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;static void PrintDateTime(CONST struct _tm *stm)&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
defines a void function called &amp;lt;code&amp;gt;PrintDateTime&amp;lt;/code&amp;gt; with a pointer (stm) to the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure as parameter.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;printf(&amp;quot;%s, %02d. %s %04d, %02d:%02d:%02d&amp;quot;, weekday_name[stm-&amp;gt;tm_wday],&lt;br /&gt;
        stm-&amp;gt;tm_mday, month_name[stm-&amp;gt;tm_mon], stm-&amp;gt;tm_year + 1900,&lt;br /&gt;
        stm-&amp;gt;tm_hour, stm-&amp;gt;tm_min, stm-&amp;gt;tm_sec);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Prints out the time and date, stored in the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure. In the case of &amp;lt;code&amp;gt;weekday_name&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;month_name&amp;lt;/code&amp;gt; it replaces the content of the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure, by the corresponding strings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;static void DisplayLocalTime(void)&lt;br /&gt;
{&lt;br /&gt;
    time_t tt;&lt;br /&gt;
    struct _tm *ltm;&lt;br /&gt;
 &lt;br /&gt;
    while (!kbhit()) {&lt;br /&gt;
        tt = time(NULL);&lt;br /&gt;
        ltm = localtime(&amp;amp;tt);&lt;br /&gt;
        PrintDateTime(ltm);&lt;br /&gt;
        printf(&amp;quot;\r&amp;quot;);&lt;br /&gt;
        NutSleep(100);&lt;br /&gt;
    }&lt;br /&gt;
    putchar('\n');&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Defines a variable &amp;quot;tt&amp;quot; of the type &amp;lt;code&amp;gt;type_t&amp;lt;/code&amp;gt;, which holds the calendar time (seconds since the start of the Unix epoche), and a pointer to the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure.&lt;br /&gt;
&lt;br /&gt;
The following &amp;lt;code&amp;gt; while (!kbhit())&amp;lt;/code&amp;gt; loop cycles as long as no keyboard hit occured, gets the system time (if already stored, passes it to the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure and passes the content of the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure to the &amp;lt;code&amp;gt;PrintTimeDate&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;printf(&amp;quot;\r&amp;quot;)&amp;lt;/code&amp;gt; causes a carriage return, followed by a &amp;lt;code&amp;gt;NutSleep(100)&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
By that the output line gets refreshed every 100ms.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;int main(void)&amp;lt;/source&amp;gt;&lt;br /&gt;
declares the main function, the first function that will be executed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;u_long baud = 115200;&amp;lt;/source&amp;gt;&lt;br /&gt;
Defines a variable of the type &amp;lt;code&amp;gt;u_long&amp;lt;/code&amp;gt; (32bit long), calls it &amp;quot;baud&amp;quot; and assigns the value 115200 to it.&lt;br /&gt;
&lt;br /&gt;
The following four lines register the UART device, open it, assign stdout and stdin to it and set the baudrate.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#ifdef RTC_CHIP&lt;br /&gt;
    NutRegisterRtc(&amp;amp;RTC_CHIP);&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
registers the boards RTC(Real Time Clock) chip (if available), that holds the calender time.&lt;br /&gt;
Thus it is powerded by a Goldcap capacitor it even stores the time, when the main power supply is disconnected, for some time.(Ethernut 3 only)&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
With this example it is not only possible to display but also to set the time.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;dev/board.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dev/debug.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;sys/version.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/timer.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;io.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;time.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static char *weekday_name[7] = {&lt;br /&gt;
    &amp;quot;Sunday&amp;quot;, &amp;quot;Monday&amp;quot;, &amp;quot;Tuesday&amp;quot;, &amp;quot;Wednesday&amp;quot;, &amp;quot;Thursday&amp;quot;, &amp;quot;Friday&amp;quot;, &amp;quot;Saturday&amp;quot;};&lt;br /&gt;
static char *month_name[12] = {&lt;br /&gt;
    &amp;quot;January&amp;quot;, &amp;quot;February&amp;quot;, &amp;quot;March&amp;quot;, &amp;quot;April&amp;quot;, &amp;quot;May&amp;quot;, &amp;quot;June&amp;quot;, &amp;quot;July&amp;quot;, &amp;quot;August&amp;quot;, &amp;quot;September&amp;quot;, &amp;quot;October&amp;quot;, &amp;quot;November&amp;quot;, &amp;quot;December&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
static void PrintDateTime(CONST struct _tm *stm)&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%s, %02d. %s %04d, %02d:%02d:%02d&amp;quot;,&lt;br /&gt;
        weekday_name[stm-&amp;gt;tm_wday],&lt;br /&gt;
        stm-&amp;gt;tm_mday, month_name[stm-&amp;gt;tm_mon], stm-&amp;gt;tm_year + 1900,&lt;br /&gt;
        stm-&amp;gt;tm_hour, stm-&amp;gt;tm_min, stm-&amp;gt;tm_sec);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int EnterDate(struct _tm *stm)&lt;br /&gt;
{&lt;br /&gt;
    int year;&lt;br /&gt;
    int mon;&lt;br /&gt;
    int mday;&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Enter date\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Year(YYYY): &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;, &amp;amp;year);&lt;br /&gt;
    stm-&amp;gt;tm_year = year - 1900;&lt;br /&gt;
    printf(&amp;quot;%04d&amp;quot;, stm-&amp;gt;tm_year + 1900);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;\nMonth(MM): &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;, &amp;amp;mon);&lt;br /&gt;
    stm-&amp;gt;tm_mon = mon - 1;&lt;br /&gt;
    printf(&amp;quot;%02d&amp;quot;, stm-&amp;gt;tm_mon + 1);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;\nDay(DD): &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;, &amp;amp;mday);&lt;br /&gt;
    stm-&amp;gt;tm_mday = mday;&lt;br /&gt;
    printf(&amp;quot;%02d  (%s)&amp;quot;, stm-&amp;gt;tm_mday, weekday_name[stm-&amp;gt;tm_wday]);&lt;br /&gt;
&lt;br /&gt;
    putchar('\n');&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int EnterTime(struct _tm *stm)&lt;br /&gt;
{&lt;br /&gt;
    int hour;&lt;br /&gt;
    int minute;&lt;br /&gt;
    int second;&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Enter time, use 24h format\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;Hours: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;, &amp;amp;hour);&lt;br /&gt;
    stm-&amp;gt;tm_hour = hour;&lt;br /&gt;
    printf(&amp;quot;%02d&amp;quot;, stm-&amp;gt;tm_hour);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;\nMinutes: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;, &amp;amp;minute);&lt;br /&gt;
    stm-&amp;gt;tm_min = minute;&lt;br /&gt;
    printf(&amp;quot;%02d&amp;quot;, stm-&amp;gt;tm_min);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;\nSeconds: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;, &amp;amp;second);&lt;br /&gt;
    stm-&amp;gt;tm_sec = second;&lt;br /&gt;
    printf(&amp;quot;%02d\n\n&amp;quot;, stm-&amp;gt;tm_sec);&lt;br /&gt;
&lt;br /&gt;
    putchar('\n');&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void SetLocalTime(void)&lt;br /&gt;
{&lt;br /&gt;
    struct _tm ltm;&lt;br /&gt;
    time_t now;&lt;br /&gt;
&lt;br /&gt;
    time(&amp;amp;now);&lt;br /&gt;
    memcpy(&amp;amp;ltm, localtime(&amp;amp;now), sizeof(ltm));&lt;br /&gt;
&lt;br /&gt;
    if (EnterDate(&amp;amp;ltm) == 0 &amp;amp;&amp;amp; EnterTime(&amp;amp;ltm) == 0) {&lt;br /&gt;
        now = mktime(&amp;amp;ltm);&lt;br /&gt;
        stime(&amp;amp;now);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void DisplayLocalTime(void)&lt;br /&gt;
{&lt;br /&gt;
    time_t tt;&lt;br /&gt;
    struct _tm *ltm;&lt;br /&gt;
&lt;br /&gt;
    while (!kbhit()) {&lt;br /&gt;
        tt = time(NULL);&lt;br /&gt;
        ltm = localtime(&amp;amp;tt);&lt;br /&gt;
        PrintDateTime(ltm);&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;\r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        NutSleep(100);&lt;br /&gt;
    }&lt;br /&gt;
    putchar('\n');&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    u_long baud = 115200;&lt;br /&gt;
    NutRegisterDevice(&amp;amp;DEV_UART, 0, 0);&lt;br /&gt;
    freopen(DEV_UART_NAME, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
    freopen(DEV_UART_NAME, &amp;quot;r&amp;quot;, stdin);&lt;br /&gt;
    _ioctl(_fileno(stdout), UART_SETSPEED, &amp;amp;baud);&lt;br /&gt;
&lt;br /&gt;
    #ifdef RTC_CHIP&lt;br /&gt;
        (NutRegisterRtc(&amp;amp;RTC_CHIP));&lt;br /&gt;
    #endif&lt;br /&gt;
&lt;br /&gt;
    SetLocalTime();&lt;br /&gt;
    DisplayLocalTime();&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
&lt;br /&gt;
This example contains 3 additional functions: &amp;lt;code&amp;gt;EnterDate&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;EnterTime&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SetLocalTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
static int EnterDate(struct _tm *stm)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
defines a function with a pointer to the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure as parameter.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
printf(&amp;quot;Hours: &amp;quot;);&lt;br /&gt;
scanf(&amp;quot;%d&amp;quot;, &amp;amp;hour);&lt;br /&gt;
stm-&amp;gt;tm_hour = hour;&lt;br /&gt;
printf(&amp;quot;%02d&amp;quot;, stm-&amp;gt;tm_hour);&lt;br /&gt;
 &lt;br /&gt;
printf(&amp;quot;\nMinutes: &amp;quot;);&lt;br /&gt;
scanf(&amp;quot;%d&amp;quot;, &amp;amp;minute);&lt;br /&gt;
stm-&amp;gt;tm_min = minute;&lt;br /&gt;
printf(&amp;quot;%02d&amp;quot;, stm-&amp;gt;tm_min);&lt;br /&gt;
 &lt;br /&gt;
printf(&amp;quot;\nSeconds: &amp;quot;);&lt;br /&gt;
scanf(&amp;quot;%d&amp;quot;, &amp;amp;second);&lt;br /&gt;
stm-&amp;gt;tm_sec = second;&lt;br /&gt;
printf(&amp;quot;%02d\n\n&amp;quot;, stm-&amp;gt;tm_sec);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;scanf&amp;lt;/code&amp;gt; statements store the user input in a local variable. Then the value gets stored in the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure through the &amp;lt;code&amp;gt;stm&amp;lt;/code&amp;gt; pointer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
static int EnterTime(struct _tm *stm)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
behaves analog.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
static void SetLocalTime(void)&lt;br /&gt;
{&lt;br /&gt;
    struct _tm ltm;&lt;br /&gt;
    time_t now;&lt;br /&gt;
 &lt;br /&gt;
    time(&amp;amp;now);&lt;br /&gt;
    memcpy(&amp;amp;ltm, localtime(&amp;amp;now), sizeof(ltm));&lt;br /&gt;
 &lt;br /&gt;
    if (EnterDate(&amp;amp;ltm) == 0 &amp;amp;&amp;amp; EnterTime(&amp;amp;ltm) == 0) {&lt;br /&gt;
        now = mktime(&amp;amp;ltm);&lt;br /&gt;
        stime(&amp;amp;now);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
defines a variable &amp;quot;ltm&amp;quot; of the structure type &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; and a variable &amp;quot;now&amp;quot; of type &amp;lt;code&amp;gt;time_t&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;time(&amp;amp;now)&amp;lt;/code&amp;gt; stores the current calender time in &amp;lt;code&amp;gt;now&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;memcopy&amp;lt;/code&amp;gt; now copies the return of &amp;lt;code&amp;gt;localtime(&amp;amp;now)&amp;lt;/code&amp;gt;(which converts calender time to a broken-down local time) via &amp;lt;code&amp;gt;ltm&amp;lt;/code&amp;gt; to the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure.&lt;br /&gt;
&lt;br /&gt;
Then, within the if statement, the functions &amp;lt;code&amp;gt;EnterDate(&amp;amp;ltm)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EnterTime(&amp;amp;ltm)&amp;lt;/code&amp;gt; are called. After that &amp;lt;code&amp;gt;mktime&amp;lt;/code&amp;gt; converts the content of the &amp;lt;code&amp;gt;_tm&amp;lt;/code&amp;gt; structure in calender time, which is then stored by &amp;lt;code&amp;gt;time(&amp;amp;now)&amp;lt;/code&amp;gt; in the RTC.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Caltime]]&lt;br /&gt;
* [[Time Zones]]&lt;br /&gt;
* [[RFC Date and Time Conversion]]&lt;br /&gt;
* More [[Nut/OS Examples]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ethernut.de/en/hardware/enut3/x12x6.html X1226/X1286 Realtime Clock And Calendar] About the RTC chip on Ethernut 3.0.&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Languages}}&lt;/div&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	</feed>