DateUtils.cpp 639 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "StdInc.h"
  2. #include <vstd/DateUtils.h>
  3. VCMI_LIB_NAMESPACE_BEGIN
  4. namespace vstd
  5. {
  6. DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt)
  7. {
  8. std::tm tm = *std::localtime(&dt);
  9. std::stringstream s;
  10. try
  11. {
  12. s.imbue(std::locale(""));
  13. }
  14. catch(const std::runtime_error & e)
  15. {
  16. // locale not be available - keep default / global
  17. }
  18. s << std::put_time(&tm, "%x %X");
  19. return s.str();
  20. }
  21. DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt)
  22. {
  23. std::tm tm = *std::localtime(&dt);
  24. std::stringstream s;
  25. s << std::put_time(&tm, "%Y%m%dT%H%M%S");
  26. return s.str();
  27. }
  28. }
  29. VCMI_LIB_NAMESPACE_END