time_to_iso8601.cc 668 B

123456789101112131415161718192021
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/time/time_to_iso8601.h"
  5. #include "base/check.h"
  6. #include "base/strings/stringprintf.h"
  7. #include "base/time/time.h"
  8. namespace base {
  9. std::string TimeToISO8601(const Time& t) {
  10. Time::Exploded exploded;
  11. t.UTCExplode(&exploded);
  12. return StringPrintf("%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year,
  13. exploded.month, exploded.day_of_month, exploded.hour,
  14. exploded.minute, exploded.second, exploded.millisecond);
  15. }
  16. } // namespace base