From 07b7c4942f8a7a5ee3eec8ea3f47a4dbc0c7a36d Mon Sep 17 00:00:00 2001 From: Caisking Date: Fri, 27 Jun 2025 15:30:49 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8Daod=E8=A1=A8=E7=9B=98=E7=9A=84?= =?utf8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/clock/src/AmbientClockView.cpp | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp index 0a64ad021..9f5fdd285 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp @@ -15,6 +15,7 @@ #include "ui_resource_image.h" #include #include +#include "custom_runtime.h" namespace OHOS { static constexpr uint16_t POINT_POSITION_X = 202; static constexpr uint16_t POINT_POSITION_Y = 16; @@ -182,8 +183,8 @@ bool AmbientClockView::InitView(void) 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); @@ -213,30 +214,25 @@ void AmbientClockView::InitDateTime(void) 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(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); - uint16_t realMilliSecond = static_cast((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()); } } -- 2.17.1