Parse date time string to DateTime
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
How do I parse
2018-10-01T00:00:00Z
Into an instance of DateTime
I've tried:
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
DateTime.parse('2018-10-01T00:00:00Z');
DateTime.valueOf('2018-10-01T00:00:00Z');
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
And I always get error:
ERROR: System.TypeException: Invalid date/time: 2018-10-01T00:00:00Z
apex datetime
add a comment |Â
up vote
1
down vote
favorite
How do I parse
2018-10-01T00:00:00Z
Into an instance of DateTime
I've tried:
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
DateTime.parse('2018-10-01T00:00:00Z');
DateTime.valueOf('2018-10-01T00:00:00Z');
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
And I always get error:
ERROR: System.TypeException: Invalid date/time: 2018-10-01T00:00:00Z
apex datetime
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How do I parse
2018-10-01T00:00:00Z
Into an instance of DateTime
I've tried:
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
DateTime.parse('2018-10-01T00:00:00Z');
DateTime.valueOf('2018-10-01T00:00:00Z');
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
And I always get error:
ERROR: System.TypeException: Invalid date/time: 2018-10-01T00:00:00Z
apex datetime
How do I parse
2018-10-01T00:00:00Z
Into an instance of DateTime
I've tried:
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
DateTime.parse('2018-10-01T00:00:00Z');
DateTime.valueOf('2018-10-01T00:00:00Z');
DateTime.valueOfGmt('2018-10-01T00:00:00Z');
And I always get error:
ERROR: System.TypeException: Invalid date/time: 2018-10-01T00:00:00Z
apex datetime
apex datetime
asked 24 mins ago
Robs
1,188424
1,188424
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
JSON.deserialize('"2018-10-01T00:00:00Z"', DateTime.class);
Note the extra set of double quotes - they allow the JSON parser to interpret that value.
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
add a comment |Â
up vote
0
down vote
As an alternative, you can use a regular expression to get the values into a more digestible form:
Pattern dt = Pattern.compile('(?i)(\d4)-(\d2)-(\d2)T(\d2):(\d2):(\d2)Z');
String exampleTime = '2018-10-01T00:00:00z';
Matcher m = dt.matcher(exampletime);
DateTime result;
if(m.find())
result = DateTime.newInstanceGMT(
Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)),
Integer.valueOf(m.group(3)),
Integer.valueOf(m.group(4)),
Integer.valueOf(m.group(5)),
Integer.valueOf(m.group(6))
);
system.debug(result);
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
JSON.deserialize('"2018-10-01T00:00:00Z"', DateTime.class);
Note the extra set of double quotes - they allow the JSON parser to interpret that value.
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
add a comment |Â
up vote
3
down vote
JSON.deserialize('"2018-10-01T00:00:00Z"', DateTime.class);
Note the extra set of double quotes - they allow the JSON parser to interpret that value.
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
JSON.deserialize('"2018-10-01T00:00:00Z"', DateTime.class);
Note the extra set of double quotes - they allow the JSON parser to interpret that value.
JSON.deserialize('"2018-10-01T00:00:00Z"', DateTime.class);
Note the extra set of double quotes - they allow the JSON parser to interpret that value.
answered 19 mins ago
David Reed
21.5k31640
21.5k31640
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
add a comment |Â
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
+1 Took the characters right out of my text box. ðÂÂÂ
â sfdcfox
17 mins ago
add a comment |Â
up vote
0
down vote
As an alternative, you can use a regular expression to get the values into a more digestible form:
Pattern dt = Pattern.compile('(?i)(\d4)-(\d2)-(\d2)T(\d2):(\d2):(\d2)Z');
String exampleTime = '2018-10-01T00:00:00z';
Matcher m = dt.matcher(exampletime);
DateTime result;
if(m.find())
result = DateTime.newInstanceGMT(
Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)),
Integer.valueOf(m.group(3)),
Integer.valueOf(m.group(4)),
Integer.valueOf(m.group(5)),
Integer.valueOf(m.group(6))
);
system.debug(result);
add a comment |Â
up vote
0
down vote
As an alternative, you can use a regular expression to get the values into a more digestible form:
Pattern dt = Pattern.compile('(?i)(\d4)-(\d2)-(\d2)T(\d2):(\d2):(\d2)Z');
String exampleTime = '2018-10-01T00:00:00z';
Matcher m = dt.matcher(exampletime);
DateTime result;
if(m.find())
result = DateTime.newInstanceGMT(
Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)),
Integer.valueOf(m.group(3)),
Integer.valueOf(m.group(4)),
Integer.valueOf(m.group(5)),
Integer.valueOf(m.group(6))
);
system.debug(result);
add a comment |Â
up vote
0
down vote
up vote
0
down vote
As an alternative, you can use a regular expression to get the values into a more digestible form:
Pattern dt = Pattern.compile('(?i)(\d4)-(\d2)-(\d2)T(\d2):(\d2):(\d2)Z');
String exampleTime = '2018-10-01T00:00:00z';
Matcher m = dt.matcher(exampletime);
DateTime result;
if(m.find())
result = DateTime.newInstanceGMT(
Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)),
Integer.valueOf(m.group(3)),
Integer.valueOf(m.group(4)),
Integer.valueOf(m.group(5)),
Integer.valueOf(m.group(6))
);
system.debug(result);
As an alternative, you can use a regular expression to get the values into a more digestible form:
Pattern dt = Pattern.compile('(?i)(\d4)-(\d2)-(\d2)T(\d2):(\d2):(\d2)Z');
String exampleTime = '2018-10-01T00:00:00z';
Matcher m = dt.matcher(exampletime);
DateTime result;
if(m.find())
result = DateTime.newInstanceGMT(
Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)),
Integer.valueOf(m.group(3)),
Integer.valueOf(m.group(4)),
Integer.valueOf(m.group(5)),
Integer.valueOf(m.group(6))
);
system.debug(result);
answered 8 mins ago
sfdcfox
232k10179395
232k10179395
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235806%2fparse-date-time-string-to-datetime%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password