Skip to content

Commit 07f4102

Browse files
committed
fix conversion issue caused by locale
1 parent 810c662 commit 07f4102

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

sdk/src/utils/Utils.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,17 @@ std::string AlibabaCloud::OSS::ToGmtTime(std::time_t &t)
432432
#endif
433433

434434
#if defined(__GNUG__) && __GNUC__ < 5
435-
char tmbuff[26];
436-
strftime(tmbuff, 26, "%a, %d %b %Y %T", &tm);
435+
static const char wday_name[][4] = {
436+
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
437+
};
438+
static const char mon_name[][4] = {
439+
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
440+
};
441+
char tmbuff[26];
442+
snprintf(tmbuff, sizeof(tmbuff), "%.3s, %.2d %.3s %d %.2d:%.2d:%.2d",
443+
wday_name[tm.tm_wday], tm.tm_mday, mon_name[tm.tm_mon],
444+
1900 + tm.tm_year,
445+
tm.tm_hour, tm.tm_min, tm.tm_sec);
437446
date << tmbuff << " GMT";
438447
#else
439448
date.imbue(std::locale::classic());
@@ -453,7 +462,7 @@ std::string AlibabaCloud::OSS::ToUtcTime(std::time_t &t)
453462
#endif
454463
#if defined(__GNUG__) && __GNUC__ < 5
455464
char tmbuff[26];
456-
strftime(tmbuff, 26, "%Y-%m-%dT%X.000Z", &tm);
465+
strftime(tmbuff, 26, "%Y-%m-%dT%H:%M:%S.000Z", &tm);
457466
date << tmbuff;
458467
#else
459468
date.imbue(std::locale::classic());

0 commit comments

Comments
 (0)