After receiving a stringVariable
from the backend service, I successfully converted it into a Date field with the following code snippet.
date d = new Date(stringVariable );
While this conversion worked fine, the resulting date format is not what I require:
Thu Jun 29 2017 20:00:00 GMT-0400 (Eastern Daylight Time)
I need to change this format to yyyy-mm-dd
while keeping the variable 'd' as a Date type rather than converting it to a String.
If I try using date pipe transform method or .toLocaleString
, it will inadvertently convert the final output of 'd' to a string, which is not desired.
Any assistance from experts would be greatly appreciated.