설명한 동작을 수행하려면 sprintf과 strcmp의 조합을 사용할 수 있습니다. this
// date and time from RTC
DateTime now = rtc.now();
// date and time to compare with - this is provided by you
String datetimeCompare = "1970/01/01 00:00:00";
// this buffer must be big enough for your complete datetime (depending on the format)
char datetimeBuffer[20] = "";
// convert current date and time to your specific format
sprintf(datetimeBuffer, "%04d/%02d/%02d %02d:%02d:%02d", now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
// perform the comparison
if(strcmp(datetimeBuffer, datetimeCompare.c_str()) == 0)
{
// datetime strings are the same
}
또는 유사 당신은 arduino stackexchange에 걸쳐 설명 된대로 형식에 따라 rtc.now() 날짜 시간을 변환합니다.
출처
2017-06-14 11:16:48
BNT
'now()'는 문자열이나 int가 아닌'DateTime' 객체를 반환합니다. –
가능한 [C++에서 문자열을 datetime으로 변환하는 방법] (http://stackoverflow.com/questions/4781852/how-to-convert-a-string-to-datetime-in-c) – Shawn
게시 할 수 있습니다 당신의 완전한 예, 특히 당신이 수행하려고하는 비교? – BNT