DateUtils.cpp 680 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * DateUtils.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include <vstd/DateUtils.h>
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. namespace vstd
  14. {
  15. DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt, std::string format)
  16. {
  17. std::tm tm = *std::localtime(&dt);
  18. std::stringstream s;
  19. s << std::put_time(&tm, format.c_str());
  20. return s.str();
  21. }
  22. DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt)
  23. {
  24. return getFormattedDateTime(dt, "%Y%m%dT%H%M%S");
  25. }
  26. }
  27. VCMI_LIB_NAMESPACE_END