#include "ui_resource_image.h"
#include <sstream>
#include <sys/time.h>
+#include "custom_runtime.h"
namespace OHOS {
static constexpr uint16_t POINT_POSITION_X = 202;
static constexpr uint16_t POINT_POSITION_Y = 16;
if (timerlabel == nullptr) {
timerlabel = new UILabel();
}
- timerlabel->SetPosition(58, 108); // widget's left position and top position
- timerlabel->Resize(350, 250); // widget's width and height
+ timerlabel->SetPosition(33, 108); // widget's left position and top position
+ timerlabel->Resize(400, 250); // widget's width and height
timerlabel->SetViewId("label1");// Set style
timerlabel->SetStyle(STYLE_TEXT_FONT, 130);
void AmbientClockView::UpdateTime(void)
{
- struct timeval tv;
- gettimeofday(&tv, nullptr);
- uint64_t second = tv.tv_sec;
- uint64_t uSecond = tv.tv_usec;
- uint64_t minute = second / MIN_TO_HOUR;
- uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR);
- uint8_t realHour = static_cast<uint8_t>(hour % HOURLY_SYSTEM);
- uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
- uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) *
- SEC_TO_MILLI + uSecond / USEC_TO_MILLI);
-
- // if (timerlabel != nullptr) {
- // std::stringstream ss;
- // ss.fill('0');
-
- // ss << std::setw(2) << realHour << ":";
- // ss << std::setw(2) << realMinute;
-
- // timerlabel->SetText(ss.str().c_str());
- // }
- if(timerlabel == nullptr)
- return;
-
- timerlabel->SetText((std::to_string(realHour) + ":" + std::to_string(realMinute)).c_str());
+ /*获取时间*/
+ struct timeval tv;
+ struct tm tblock_;
+ gettimeofday(&tv, NULL); // 获取当前时间
+ localtime_r(&tv.tv_sec, &tblock_);
+
+ std::ostringstream oss;
+
+ //需要判断显示的格式
+ if (uapi_dev_runtime_get_time_hour_show_model() == 12)
+ {
+ if (tblock_.tm_hour > 12)
+ tblock_.tm_hour = tblock_.tm_hour - 12 ;
+ }
+
+ oss << std::setw(2) << std::setfill('0') << tblock_.tm_hour << ":"
+ << std::setw(2) << std::setfill('0') << tblock_.tm_min;
+
+ timerlabel->SetText(oss.str().c_str());
}
}