#include "Arduino.h"
#include <TimeLib.h> //
https://github.com/PaulStoffregen/Time
// dow() 曜日を示す数値を戻す[0-Sunday, 1-Monday etc.]
uint8_t dow(unsigned long t) {
return ((t / 86400) + 4) % 7;
}
// dow_char() 曜日文字を戻す [日曜,火曜....]
char * dow_char_JP(byte days) {
const char *you[] =
{"日曜","月曜","火曜","水曜","木曜","金曜","土曜"};
return (char *)you[days];
}
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.print("UNIX_TIME=");
Serial.println(UNIX_TIME);
unsigned long epoch = atol(UNIX_TIME);
//Serial.print("epoch=");
//Serial.println(epoch);
// Timeライブラリに時間を設定(UNIXタイム)
// 日本標準時にあわせるために+9時間しておく
setTime(epoch + (9 * 60 * 60));
Serial.print("JST time = ");
Serial.print(year());
Serial.print('/');
Serial.print(month());
Serial.print('/');
Serial.print(day());
Serial.print(' ');
Serial.print(hour());
Serial.print(':');
Serial.print(minute());
Serial.print(':');
Serial.print(second());
Serial.print(" ");
uint8_t DayOfWeek = dow(epoch + (9 * 60 * 60));
Serial.print(dow_char_JP(DayOfWeek));
Serial.println();
delay(1000);
} |