Formatting Datetime.now()JSON.serialize is mucking with my datetime objects. How do I fix this?DateTime.Format() Documentation example causes exceptionTab (t character) Substitute In VisualforceCombine Date from one datetime field with Time from anotherHow to parse Setup Audit Trail's Date formatQuestion on date fields in visualforce pageHelp in converting string to datetime in correct formatWhat's the correct format to set a default value to a DateTime aura:attribute?Need to display the supported locale date formatConvert String into formated dateHow to correctly read CSV file, BLOB not UTF-8 stringDateTime Convertions
Why is "breaking the mould" positively connoted?
Mug and wireframe entirely disappeared
Why is my arithmetic with a long long int behaving this way?
Is there a word for food that's gone 'bad', but is still edible?
Would you use "llamarse" for an animal's name?
What is this weird transparent border appearing inside my Smart Object in Photoshop?
Notation: What does the tilde bellow of the Expectation mean?
Typeset year in old-style numbers with biblatex
Which US defense organization would respond to an invasion like this?
Find magical solution to magical equation
Should homeowners insurance cover the cost of the home?
Latex & Markdown files
It is as simple as ABC
Is Benjen dead?
Adding command shortcuts to /bin
How should I tell my manager I'm not paying for an optional after work event I'm not going to?
How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?
Any examples of liquids volatile at room temp but non-flammable?
getline() vs. fgets(): Control memory allocation
What do "Sech" and "Vich" mean in this sentence?
Will 700 more planes a day fly because of the Heathrow expansion?
Why do people keep telling me that I am a bad photographer?
Can muons decay into quarks?
How does summation index shifting work?
Formatting Datetime.now()
JSON.serialize is mucking with my datetime objects. How do I fix this?DateTime.Format() Documentation example causes exceptionTab (t character) Substitute In VisualforceCombine Date from one datetime field with Time from anotherHow to parse Setup Audit Trail's Date formatQuestion on date fields in visualforce pageHelp in converting string to datetime in correct formatWhat's the correct format to set a default value to a DateTime aura:attribute?Need to display the supported locale date formatConvert String into formated dateHow to correctly read CSV file, BLOB not UTF-8 stringDateTime Convertions
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to format my Datetime.now() to be accepted for a SOAP request.
I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z
Currently I have tried: .format(), .formatLong(), Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.
apex datetime formatting
add a comment |
I need to format my Datetime.now() to be accepted for a SOAP request.
I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z
Currently I have tried: .format(), .formatLong(), Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.
apex datetime formatting
add a comment |
I need to format my Datetime.now() to be accepted for a SOAP request.
I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z
Currently I have tried: .format(), .formatLong(), Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.
apex datetime formatting
I need to format my Datetime.now() to be accepted for a SOAP request.
I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z
Currently I have tried: .format(), .formatLong(), Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.
apex datetime formatting
apex datetime formatting
asked 2 hours ago
OliviaOlivia
1,417427
1,417427
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')
Just do the same thing with the Z:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')
Note that Z is a valid argument in SimpleDateFormat:
Letter Date or Time Component Presentation Examples
... ... ... ...
Z Time zone RFC 822 time zone -0800
See also:
- DateTime.Format() Documentation example causes exception
- JSON.serialize is mucking with my datetime objects. How do I fix this?
- Salesforce Apex: ISO Timestamp Format Function
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
add a comment |
Another approach
String s = JSON.serialize(Datetime.now()).replace('"','');
or
String s = JSON.serialize(Datetime.now()).substringBetween('"');
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f261098%2fformatting-datetime-now%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')
Just do the same thing with the Z:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')
Note that Z is a valid argument in SimpleDateFormat:
Letter Date or Time Component Presentation Examples
... ... ... ...
Z Time zone RFC 822 time zone -0800
See also:
- DateTime.Format() Documentation example causes exception
- JSON.serialize is mucking with my datetime objects. How do I fix this?
- Salesforce Apex: ISO Timestamp Format Function
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
add a comment |
You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')
Just do the same thing with the Z:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')
Note that Z is a valid argument in SimpleDateFormat:
Letter Date or Time Component Presentation Examples
... ... ... ...
Z Time zone RFC 822 time zone -0800
See also:
- DateTime.Format() Documentation example causes exception
- JSON.serialize is mucking with my datetime objects. How do I fix this?
- Salesforce Apex: ISO Timestamp Format Function
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
add a comment |
You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')
Just do the same thing with the Z:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')
Note that Z is a valid argument in SimpleDateFormat:
Letter Date or Time Component Presentation Examples
... ... ... ...
Z Time zone RFC 822 time zone -0800
See also:
- DateTime.Format() Documentation example causes exception
- JSON.serialize is mucking with my datetime objects. How do I fix this?
- Salesforce Apex: ISO Timestamp Format Function
You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')
Just do the same thing with the Z:
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')
Note that Z is a valid argument in SimpleDateFormat:
Letter Date or Time Component Presentation Examples
... ... ... ...
Z Time zone RFC 822 time zone -0800
See also:
- DateTime.Format() Documentation example causes exception
- JSON.serialize is mucking with my datetime objects. How do I fix this?
- Salesforce Apex: ISO Timestamp Format Function
edited 20 mins ago
David Cheng
2,61452047
2,61452047
answered 2 hours ago
Adrian Larson♦Adrian Larson
111k19123262
111k19123262
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
add a comment |
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
ah I forgot to escape the Z. Thank you, you're the best!
– Olivia
2 hours ago
add a comment |
Another approach
String s = JSON.serialize(Datetime.now()).replace('"','');
or
String s = JSON.serialize(Datetime.now()).substringBetween('"');
add a comment |
Another approach
String s = JSON.serialize(Datetime.now()).replace('"','');
or
String s = JSON.serialize(Datetime.now()).substringBetween('"');
add a comment |
Another approach
String s = JSON.serialize(Datetime.now()).replace('"','');
or
String s = JSON.serialize(Datetime.now()).substringBetween('"');
Another approach
String s = JSON.serialize(Datetime.now()).replace('"','');
or
String s = JSON.serialize(Datetime.now()).substringBetween('"');
answered 1 hour ago
cropredycropredy
36.7k444126
36.7k444126
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f261098%2fformatting-datetime-now%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown