#include <array>
#include <iostream>
#include <string>
std::string GetDateFormatString(const std::string& langCode)
{
if (
0 == langCode.compare(0, 2, "en")
|| 0 == langCode.compare(0, 2, "EN")
)
{
return std::string("%1$i/%2$i/%3$i");
}
else if (
0 == langCode.compare(0, 2, "fr")
|| 0 == langCode.compare(0, 2, "FR")
)
{
return std::string("%2$i/%1$i/%3$i");
}
else if (
0 == langCode.compare(0, 2, "ja")
|| 0 == langCode.compare(0, 2, "JA")
|| 0 == langCode.compare(0, 2, "jp")
|| 0 == langCode.compare(0, 2, "JP")
)
{
return std::string("%3$i/%2$i/%1$i");
}
return std::string("%1$i/%2$i/%3$i");
}
std::string GetDateString(
const std::string& langCode,
int month, int day, int year)
{
std::string fmt = GetDateFormatString(langCode);
std::array<char, 32> buffer;
buffer.fill(0);
#if defined(_WIN32)
::_sprintf_p(buffer.data(), 32, fmt.c_str(), month, day, year);
#else
::sprintf(buffer.data(), fmt.c_str(), month, day, year);
#endif
std::string ret = buffer.data();
return ret;
}
int main()
{
std::cout << GetDateString("en", 11, 7, 2018) << "\n";
return 0;
}
I2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiAKc3RkOjpzdHJpbmcgR2V0RGF0ZUZvcm1hdFN0cmluZyhjb25zdCBzdGQ6OnN0cmluZyYgbGFuZ0NvZGUpCnsKICAgIGlmICgKICAgICAgIDAgPT0gbGFuZ0NvZGUuY29tcGFyZSgwLCAyLCAiZW4iKQogICAgICAgfHwgMCA9PSBsYW5nQ29kZS5jb21wYXJlKDAsIDIsICJFTiIpCiAgICAgICApCiAgICB7CiAgICAgICAgcmV0dXJuIHN0ZDo6c3RyaW5nKCIlMSRpLyUyJGkvJTMkaSIpOwogICAgfQogICAgZWxzZSBpZiAoCiAgICAgICAwID09IGxhbmdDb2RlLmNvbXBhcmUoMCwgMiwgImZyIikKICAgICAgIHx8IDAgPT0gbGFuZ0NvZGUuY29tcGFyZSgwLCAyL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