Can't use Time.h - alternatives?

I am constantly having trouble with time.h in my builds. I am tired of trying to debug the situation.

Does anyone have any suggestions on how to get a time string like the following with out a library?

char cTime[22];

sprintf(cTime, "%04d%02d%02d:%02d%02d%02d", year(), month(), day(), hour(), minute(), second());

Serial.println(cTime);

Thank you.

I am constantly having trouble with time.h in my builds.

Feel free to not tell us about them.

Does anyone have any suggestions on how to get a time string like the following with out a library?

Where do you intend to get the functions? Where are they going to get values?

Do yourself a favor. Get an RTC.

You're defining cTime as a char array and expect it to behave like a clock? Treat your child as a refrigerator and I'm sure you'll find he's lousy at keeping your beer cool.

If you are getting compile time errors then the problem may be in the DateStrings.cpp. If so either download an up to date copy of the library or a fixed DateStrings.cpp from here.

It may also be useful to tell us what the actual problem is rather than keeping us guessing and when it is fixed let us know.

It may also be useful to tell us what the actual problem is rather than keeping us guessing and when it is fixed let us know.

yeah, I use the Time library a lot... I don't recall it had issues.

Thank you for your replies.

I am sorry if I pissed you guys off. I am real new to this arduino stuff. I am a database dev by day and working with linux, c, c++ is greek to me.

Here is the sketch, not even using time.h, just adding it to the include blows the build.

#include "arduino.h"
#include <Time.h>

int ledPin = 13;
int inputPin = 8;
int pirState = LOW;
int val = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
Serial.println("setup");
attachInterrupt(8, getMotion, RISING);
}

void getMotion()
{
Serial.print("8 is HIGH");
Serial.println(second());
}

void loop()
{
}


Here is the error

Board Properties
name=IntelĀ® Edison
upload.tool=izmirdl
upload.protocol=sam-ba
upload.maximum_size=10000000
upload.use_1200bps_touch=false
upload.wait_for_upload_port=false
upload.native_usb=false
build.mcu=i686
build.f_cpu=-m32
build.core=arduino
build.variant=edison_fab_c
build.toolchain_path=x86_64-pokysdk-linux-eglibc/usr/bin/i586-poky-linux
build.sysroot_path=i586-poky-linux-eglibc
build.toolchain_prefix=i586-poky-linux-
runtime.ide.path=E:\Ard104
build.system.path=E:\Ard104\hardware\arduino\edison\system
runtime.ide.version=153
originalid=izmir_ec
compiler.toolchain.path={runtime.ide.path}/hardware/tools/edison
compiler.prefix=i586-poky-linux
compiler.path={compiler.toolchain.path}/sysroots/i686-pokysdk-mingw32/usr/bin/i586-poky-linux/
compiler.sysroot={compiler.toolchain.path}/sysroots/core2-32-poky-linux
compiler.c.cmd={compiler.prefix}-gcc
compiler.c.flags=-m32 -march=i586 --sysroot={compiler.sysroot} -c -g -Os -w -ffunction-sections -fdata-sections -MMD -D__ARDUINO_X86__
compiler.c.elf.flags=-m32 -march=i586 --sysroot={compiler.sysroot} -Os -Wl,--gc-sections

Compiling 'PIR' for 'IntelĀ® Edison'
Build folder: file:///C:/Users/Terrence/AppData/Local/VMicro/Arduino/Builds/PIR/izmir_ec
fcntl.h:In file included from
fast_gpio_common.c:from
stat.h:91:21: error: field 'st_atim' has incomplete type
:struct timespec st_atim; * Time of last access. *
:^
stat.h:92:21: error: field 'st_mtim' has incomplete type
:struct timespec st_mtim; * Time of last modification. *
:^
stat.h:93:21: error: field 'st_ctim' has incomplete type
:struct timespec st_ctim; * Time of last status change. *
:^
fcntl.h:In file included from
variant.cpp:from
stat.h:91:21: error: field 'st_atim' has incomplete type
:struct timespec st_atim; * Time of last access. *
:^
stat.h:92:21: error: field 'st_mtim' has incomplete type
:struct timespec st_mtim; * Time of last modification. *
:^
stat.h:93:21: error: field 'st_ctim' has incomplete type
:struct timespec st_ctim; * Time of last status change. *
:^
stat.h:152:21: error: field 'st_atim' has incomplete type
:struct timespec st_atim; * Time of last access. *
:^
stat.h:153:21: error: field 'st_mtim' has incomplete type
:struct timespec st_mtim; * Time of last modification. *
:^
stat.h:154:21: error: field 'st_ctim' has incomplete type
:struct timespec st_ctim; * Time of last status change. *
:^
Error compiling core

Ken thank you for your help.

You're defining cTime as a char array and expect it to behave like a clock?

What would you suggest instead of a char array? I don't want a clock, I am just formatting the datetime so I can store it in Azure Tablestorage.

Treat your child as a refrigerator and I'm sure you'll find he's lousy at keeping your beer cool.
I do not like warm beer. Please help me avoid that situation.

Paul thank you for your reply.

Where do you intend to get the functions? Where are they going to get values?

I don't know, I figured there was a base function somewhere that would return a date and I could parse that, or you guys could help me parse it.

Do yourself a favor. Get an RTC.

Adding an rtc would complicate my system. Do you think I need one if all I want is to format the datetime into a string for storage in the cloud?

Do yourself a favor. Get an RTC
Turns out my Intel Edison board has a RTC, but no coin battery to keep it up to date. When the board boots up it NTPs and gets the time from a server.

This doesn't help you much, but that code compiles fine with an Uno selected as the target.

I suspect therefore that you have some issue with your install - what version supports the Edison?

As an aside, note that it's a bad idea to use serial.print in an interrupt. Set a volatile flag in the interrupt and move the serial prints to loop, controlled by the flag.

Do you think I need one if all I want is to format the datetime into a string for storage in the cloud?

Maybe not, but without an RTC or another source of accurate time the Arduino is going to be a terrible timekeeper.

Also an RTC module is not expensive, especially the less accurate DS1307. It only requires an I2C connection.