Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <locale>
- #include <windows.h>
- #include <tchar.h>
- #include <locale>
- #include <ctime>
- #include <string>
- #include <sstream>
- using namespace std;
- string get_date_string(const time_t &inputTime, const locale &loc) {
- auto time = localtime(&inputTime);
- // get time_put facet:
- const auto& tmput = std::use_facet <time_put<char> >(loc);
- stringstream s;
- s.imbue(loc);//set locale loc to the stream, no matter which global locale
- const auto myTime = localtime(&inputTime);
- tmput.put(s, s, ' ', myTime, 'x');
- return s.str();
- }
- int main()
- {
- WCHAR localeNameBuffer[100];
- GetUserDefaultLocaleName(localeNameBuffer, 100);
- wstring ws(localeNameBuffer);
- const string localeName(ws.begin(), ws.end());
- cout << localeName << endl;
- time_t timestamp;
- time(×tamp);
- cout << "American English: " << get_date_string(timestamp, locale(localeName)) << "\n";
- cout << "Foreign Language: " << get_date_string(timestamp, locale("sv-se")) << "\n";
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment