--example------------------------------------------------------------
unsigned long tm ;
char buff[12] ;
tm = millis() ;
ctime(tm,(char *)buff) ;
Serial.println(buff) ;
--切り取り線---------------------------------------------------------
/*******************************************************************************
* ctime(tm,buff) *
* millis関数の時間を日/時間:分:秒の文字列に変換する処理 *
* *
* tm : millis関数から返された時間を指定する *
* buff : 日/時間:分:秒に変換したデータを格納するバッファ *
*******************************************************************************/
void ctime(unsigned long tm,char *buff)
{
unsigned long time ;
unsigned long day , h , m , s ;
char c[6] ;
day = tm / 86400000L ; // 日(0-5)
h = tm / 3600000L ; // 時間(0-120)
time = tm % 3600000L ;
if (time != 0L) {
m = time / 60000L ; // 分(0-59)
time = time % 60000L ;
if (time != 0L) {
s = time / 1000L ; // 秒(0-59)
} else s = 0 ;
} else m = s = 0 ;
// 文字列に変換
sprintf(buff,"%d/",day) ;
sprintf(c,"%d:",h) ;
strcat(buff,c) ;
sprintf(c,"%d:",m) ;
strcat(buff,c) ;
sprintf(c,"%d",s) ;
strcat(buff,c) ;
}
--切り取り線---------------------------------------------------------
【きむ茶工房ガレージハウス】
Copyright (C) 2006-2011 Shigehiro Kimura All Rights Reserved.