I have timestamps -
deliveryDateFrom: 1632767400000
deliveryDateTo: 1632853799000
I want to get date in this format - Example - "Tuesday , June 13th Between 11am and 2pm"
How can we get this?
tried these -
var date = new Date(1313564400000);
var month = date.getMonth();
var date = new Date(timestamp);
let year = date.getFullYear();
let month = date.getMonth() 1;
let day = date.getDate();
But could not understand it. Note - I am new to angular.
CodePudding user response:
So first we create the day:
let date = new Date(1632767400000)
To get the weekday you can do this:
let firstDate = date.toLocaleString('en-us', {month: 'long', day:'numeric', weekday: 'long'});
In your case this will output 'Monday, September 27'.
And then add the 'th' behind the 27
firstdate = firstdate 'th';
To then get the 12 hour version of the first and second date we can do this
let firstDateHours = date.toLocaleString('en-us', {hour: 'numeric', hour12: true});
let secondDate = new Date(1632853799000);
let secondDateHours = date.toLocaleString('en-us', {hour: 'numeric', hour12: true});
This will output 8PM
These variables will have to be public but it will look something like this
To then put this all together you will put this in your html template
{{${firstDate} Between ${firstDateHours} and ${secondDateHours}
}}
this will show the following in your template:
Monday, September 27th Between 8pm and 8pm
I hope this helps you on your way.
Results will vary depending on your timestamps