Example showing how to use set_time().

Committer:
RalphF
Date:
Wed Mar 13 19:45:12 2019 +0000
Revision:
0:12113f70aa84
First release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RalphF 0:12113f70aa84 1 /* mbed Example Program
RalphF 0:12113f70aa84 2 * Copyright (c) 2006-2014 ARM Limited
RalphF 0:12113f70aa84 3 *
RalphF 0:12113f70aa84 4 * Licensed under the Apache License, Version 2.0 (the "License");
RalphF 0:12113f70aa84 5 * you may not use this file except in compliance with the License.
RalphF 0:12113f70aa84 6 * You may obtain a copy of the License at
RalphF 0:12113f70aa84 7 *
RalphF 0:12113f70aa84 8 * http://www.apache.org/licenses/LICENSE-2.0
RalphF 0:12113f70aa84 9 *
RalphF 0:12113f70aa84 10 * Unless required by applicable law or agreed to in writing, software
RalphF 0:12113f70aa84 11 * distributed under the License is distributed on an "AS IS" BASIS,
RalphF 0:12113f70aa84 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
RalphF 0:12113f70aa84 13 * See the License for the specific language governing permissions and
RalphF 0:12113f70aa84 14 * limitations under the License.
RalphF 0:12113f70aa84 15 */
RalphF 0:12113f70aa84 16 #include "mbed.h"
RalphF 0:12113f70aa84 17
RalphF 0:12113f70aa84 18 int main() {
RalphF 0:12113f70aa84 19 set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
RalphF 0:12113f70aa84 20
RalphF 0:12113f70aa84 21 while (true) {
RalphF 0:12113f70aa84 22 time_t seconds = time(NULL);
RalphF 0:12113f70aa84 23
RalphF 0:12113f70aa84 24 printf("Time as seconds since January 1, 1970 = %u\n", (unsigned int)seconds);
RalphF 0:12113f70aa84 25
RalphF 0:12113f70aa84 26 printf("Time as a basic string = %s", ctime(&seconds));
RalphF 0:12113f70aa84 27
RalphF 0:12113f70aa84 28 char buffer[32];
RalphF 0:12113f70aa84 29 strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
RalphF 0:12113f70aa84 30 printf("Time as a custom formatted string = %s", buffer);
RalphF 0:12113f70aa84 31
RalphF 0:12113f70aa84 32 wait(1);
RalphF 0:12113f70aa84 33 }
RalphF 0:12113f70aa84 34 }
RalphF 0:12113f70aa84 35
RalphF 0:12113f70aa84 36