I want to display created date and time separately in LWC UI. From apex I am returning the created date but not able to get it separately. How can I get date and time separately from created date?
-
You can extract these separate components in the LWC JavaScript using standard JavaScript functionality. If, after trying this for yourself, you still have problems, please update this question to show what you've tried and where you are stuck.– Phil WCommented Jan 18, 2021 at 16:24
-
Thanks for your comment. It worked– Raj SFCommented Jan 20, 2021 at 7:24
Add a comment
|
1 Answer
Typically you just need the set the date value as a date object. Then you can use any date methods you wish to display the day and hours.
Example:
const createdDateServerValue = “yourValue”;
const createdDate = new Date(createdDateServerValue);
const dateValue = createdDate.getDate();
const hours = createdDate.getHours();