diff --git a/moto/core/utils.py b/moto/core/utils.py
index 946dd589..7d4a9d41 100644
--- a/moto/core/utils.py
+++ b/moto/core/utils.py
@@ -170,6 +170,10 @@ def iso_8601_datetime_with_milliseconds(datetime):
return datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z'
+def iso_8601_datetime_without_milliseconds(datetime):
+ return datetime.strftime("%Y-%m-%dT%H:%M:%S") + 'Z'
+
+
def rfc_1123_datetime(datetime):
RFC1123 = '%a, %d %b %Y %H:%M:%S GMT'
return datetime.strftime(RFC1123)
diff --git a/moto/iam/models.py b/moto/iam/models.py
index 456dce4a..c7142fb5 100644
--- a/moto/iam/models.py
+++ b/moto/iam/models.py
@@ -4,6 +4,7 @@ from datetime import datetime
import pytz
from moto.core import BaseBackend, BaseModel
+from moto.core.utils import iso_8601_datetime_without_milliseconds
from .exceptions import IAMNotFoundException, IAMConflictException, IAMReportNotPresentException
from .utils import random_access_key, random_alphanumeric, random_resource_id, random_policy_id
@@ -235,10 +236,7 @@ class User(BaseModel):
self.name = name
self.id = random_resource_id()
self.path = path if path else "/"
- self.created = datetime.strftime(
- datetime.utcnow(),
- "%Y-%m-%d-%H-%M-%S"
- )
+ self.created = datetime.utcnow()
self.mfa_devices = {}
self.policies = {}
self.access_keys = []
@@ -248,6 +246,10 @@ class User(BaseModel):
def arn(self):
return "arn:aws:iam::{0}:user{1}{2}".format(ACCOUNT_ID, self.path, self.name)
+ @property
+ def created_iso_8601(self):
+ return iso_8601_datetime_without_milliseconds(self.created)
+
def get_policy(self, policy_name):
policy_json = None
try:
@@ -310,7 +312,7 @@ class User(BaseModel):
def to_csv(self):
date_format = '%Y-%m-%dT%H:%M:%S+00:00'
- date_created = datetime.strptime(self.created, '%Y-%m-%d-%H-%M-%S')
+ date_created = self.created
# aagrawal,arn:aws:iam::509284790694:user/aagrawal,2014-09-01T22:28:48+00:00,true,2014-11-12T23:36:49+00:00,2014-09-03T18:59:00+00:00,N/A,false,true,2014-09-01T22:28:48+00:00,false,N/A,false,N/A,false,N/A
if not self.password:
password_enabled = 'false'
diff --git a/moto/iam/responses.py b/moto/iam/responses.py
index c56090cf..8e19b3aa 100644
--- a/moto/iam/responses.py
+++ b/moto/iam/responses.py
@@ -823,7 +823,7 @@ LIST_USERS_TEMPLATE = """<{{ action }}UsersResponse>
{{ user.id }}
{{ user.path }}
{{ user.name }}
- {{ user.created }}
+ {{ user.created_iso_8601 }}
{{ user.arn }}
{% endfor %}