如何在Tizen c程序中正确获取当前日期

问题描述 投票:0回答:1

以下程序与c编译器一起使用并返回正确的日期。但在tizen应用程序代码上它返回0:

time_t my_time;
    struct tm * timeinfo;
    time (&my_time);
    timeinfo = localtime (&my_time);

    int y = timeinfo->tm_year+1900;
    int m = timeinfo->tm_mon+1;
    int d = timeinfo->tm_mday;
 char day[10];

dlog_print(DLOG_DEBUG, "GG", "Current time: %d %d %d", y,m,d);

必需截图:

enter image description here

它仅显示日期(d)0,但其他m和y正确打印。类似的代码也会在其他c complier程序上打印正确的日期。

如何正确地获取当月的当天?

c tizen tizen-wearable-sdk
1个回答
0
投票

您可以在可穿戴配置文件上使用Watch Application API

您还可以在Tizen Studio示例应用程序(Classic Watch)中找到示例代码,如下所示。

/**
 * @brief Called at each second. This callback is not called while the app is paused or the device is in ambient mode.
 * @param[in] watch_time The watch time handle. watch_time will not be available after returning this callback. It will be freed by the framework.
 * @param[in] user_data The user data to be passed to the callback functions
 */
void app_time_tick(watch_time_h watch_time, void* user_data)
{
    int hour = 0;
    int min = 0;
    int sec = 0;
    int year = 0;
    int month = 0;
    int day = 0;
    int day_of_week = 0;

    watch_time_get_hour(watch_time, &hour);
    watch_time_get_minute(watch_time, &min);
    watch_time_get_second(watch_time, &sec);
    watch_time_get_day(watch_time, &day);
    watch_time_get_month(watch_time, &month);
    watch_time_get_year(watch_time, &year);
    watch_time_get_day_of_week(watch_time, &day_of_week);

    _set_time(hour, min, sec);
    _set_date(day, month, day_of_week);
    _set_moonphase(day, month, year);
}
© www.soinside.com 2019 - 2024. All rights reserved.