Gstreamer:从时间字符串中删除时间偏移部分

Gstreamer: Strip out time offset part from time string

我使用 GstDateTime API 将时间附加到文件名。要将时间转换成字符串,这里只有 gst_date_time_to_iso8601_string 函数, return 包含时间偏移的字符串:

2021-01-23T23:30:59+0100

我使用这部分代码从时间字符串中删除了时间偏移量:

g_autoptr (GstDateTime) date_time = NULL;
g_autofree gchar *time = NULL;
char *end;

date_time = gst_date_time_new_now_local_time ();
g_assert (date_time);

time = gst_date_time_to_iso8601_string (date_time);
/* strip out time offset from time string */
end = strrchr (time, '+');
if (end != NULL)
{
    *end = '[=11=]';
}

有没有更优雅的方法来做到这一点? 谢谢

您可以使用 gst_date_time_to_g_date_time() 得到一个 GDateTime,这将更容易使用。在您的情况下,您可以使用 g_date_time_format(gdatetime, "%F"); 仅以您想要的格式打印日期。