Guest User

Untitled

a guest
Jan 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <locale>
  5. #include <windows.h>
  6. #include <tchar.h>
  7. #include <locale>
  8. #include <ctime>
  9. #include <string>
  10. #include <sstream>
  11.  
  12. using namespace std;
  13.  
  14. string get_date_string(const time_t &inputTime, const locale &loc) {
  15. auto time = localtime(&inputTime);
  16. // get time_put facet:
  17. const auto& tmput = std::use_facet <time_put<char> >(loc);
  18.  
  19. stringstream s;
  20. s.imbue(loc);//set locale loc to the stream, no matter which global locale
  21.  
  22. const auto myTime = localtime(&inputTime);
  23. tmput.put(s, s, ' ', myTime, 'x');
  24.  
  25. return s.str();
  26. }
  27.  
  28. int main()
  29. {
  30. WCHAR localeNameBuffer[100];
  31. GetUserDefaultLocaleName(localeNameBuffer, 100);
  32. wstring ws(localeNameBuffer);
  33. const string localeName(ws.begin(), ws.end());
  34. cout << localeName << endl;
  35.  
  36. time_t timestamp;
  37. time(&timestamp);
  38.  
  39. cout << "American English: " << get_date_string(timestamp, locale(localeName)) << "\n";
  40. cout << "Foreign Language: " << get_date_string(timestamp, locale("sv-se")) << "\n";
  41.  
  42. system("pause");
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment