I want to set min date and time to ion-datetime. But I am not able to set it without converting that to toISOString().
If I am converting to toISOString() then time is not setting the exact time. It is setting the 5.30 hr previous time.
<ion-datetime text-center placeholder="Start Date"
pickerFormat="MMM-DD-YYYY hh:mm A" displayFormat="MM-DD-YYYY hh:mm A" min="{{startDate}}"></ion-datetime>
startDate: any;
this.startDate = new Date().toISOString();
Can anyone please help me how to resolve this.
You can use the moment library for this and set max date like:
this.startDate = moment.utc(new Date()).local().format('YYYY-MM-DDTHH:mm:ss.SSS');
and ion-datetime does not compare time part.
Related
Using moment to format a date retrieved from a firestore timestamp. However the date is off by at least a day, and at most, a few months. and the year is off by 50 no matter what.
Here is the firestore timestamp
EDIT: Here is whats logged from lastMsg.seconds:
1581372232
I retrieve the time in seconds in a FlatList's renderItem:
renderItem={({ item, index }) => {
return (
<Components.InboxItem
title={item.withName}
subtitle={item.lastMsg.seconds}
img={item.withImg}
/>
);
And finally inside the component I use moment like so:
const date = moment()
.utc()
.startOf('year')
.seconds(props.subtitle)
.format('MMMM DD YYYY');
While ive tried multiple format configurations, the one that gets it closest to accurate is with .startOf("year"). Even then, date is being displayed as "February 09, 2070". If .startOf() is changed to "month", "day", or "hour", the date gets changed to sometime in march. How can this be fixed to display the date as in firestore?
Looking at the https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp we can either get JS Date object or use the toMillis method to get milliseconds.
Now the simple moment.js api for converting timestamp to moment object is given here https://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/
moment(Number);
Now you can apply format on the moment object like below:
moment(Number).format(String);
Your issue with wrong date is may be due to the use of utc and seconds together and not passing timestamp to moment()
Use moment.unix():
const props = {
subtitle: 1581372232
};
const date = moment
.unix(props.subtitle)
.format('MMMM DD YYYY');
console.log(date);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
because item.lastMsg.seconds is
The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z
I want to display this time format in ion-datetime. Both date and time I want to display.
But when I am assigning this value to ngmodel it is not displaying.
Can anyone please help me how to do this.
You can use displayForamt attribute to show date like this.
Check Example blow.
<ion-item>
<ion-label>D MMM YYYY H:mm</ion-label>
<ion-datetime pickerFormat="YYYY/MM/DD H:mm:s" displayFormat="YYYY/MM/DD H:mm:ss" min="1997" max="2010" [(ngModel)]="dateN"></ion-datetime>
</ion-item>
set your date in this format YYYY/MM/DD HH:mm:ss for example 2019/08/05 09:35:07
Here is an example in your .ts file current = '2019/08/01 04:31:07'; // you can format your date to fit this
then in your html
<ion-datetime [(ngModel)]="current" displayFormat="YYYY/MM/DD HH:mm:ss" pickerFormat="YYYY/MM/DD HH:mm:ss"></ion-datetime>
displayFormat decides how you want the date-time to be displayed
I'm using momentJS to format some dates for a chartJS implementation.
In the chart i'm predicting the next 15 minutes worth of data so need to add the next 15 minutess worth of datetimes to my chartLabel variable.
I use the below function to achieve this. The issue is that the formatting for every other datetime seems to reverse the day and month. I have no idea why this is happening, has anyone seen this before?
predictMarketData(){
let lastDate = this.marketData[this.marketData.length-1][0]
lastDate = moment.unix(lastDate).add(1, 'minutes').format('DD/MM h:mm a')
for(var _i = 0; _i < 15; _i++){
this.chartLabels.push(lastDate);
lastDate = moment(lastDate).add(1, 'minutes').format('DD/MM h:mm a');
}
}
It appears to add minutes correctly but the day month formatting appears to reverse every other, screenshot provided.
Any help would be much appreciated!
I have a VB6 Datepicker with the following properties:
Format Type - Time
Min Date - 1/1/1900
Value - 12:00:00 AM
And I initialize it like this:
dtpTimeVal = TimeValue("00:00:00")
However, when I get the date value of the time picker, it returns the value 12/30/1899.
Am I missing any properties or initialization logic here?
there probably is some error where you set the format
the following works:
Private Sub Form_Load()
DTPicker1.Format = dtpTime
DTPicker1.Value = "00:00:00"
End Sub
if i remove the format line, then i get the same result as you do
Why does the ToUniversalTime function have no effect here;
DateTime dt = new DateTime(2009,3,24,1,0,0,DateTimeKind.Local);
dt = dt.ToUniversalTime(); // convert BST to UTC ?
dt.ToString();
"24/03/2009 01:00:00" ... wrong?
Is the same as..
DateTime dt = new DateTime(2009,3,24,1,0,0,DateTimeKind.Utc);
dt = dt.ToUniversalTime(); // nothing to do, already utc
dt.ToString();
"24/03/2009 01:00:00" ... correct.
I expected there to be an adjustment to the ToString() value of the first example, where by the DateTime specified as Local would result in a corresponding TimeZone calculation upon the call to ToUniversalTime() and the time in the UK should have resulted in
"24/03/2009 00:00:00" as UTC.
However it appears like the specifying of the DateTimeKind in this way renders ToUniversalTime or ToLocalTime unable to make any calculation.
Are you in the UK by any chance? Although we are now in daylight saving time, the date you specify in your code is before this switched over, so local and UTC time in the UK are the same. If you specify April as your month, then you will see a one hour difference.
Cheers David M.
Not had my breakfast. Indeed, when I repeat the test with dates that elapse the BST summer-time threshold, the behaviour is of course correct.
DateTime dt = new DateTime(2009,4,24,1,0,0,DateTimeKind.Local);
dt = dt.ToUniversalTime(); // convert BST to UTC ?
dt.ToString(); // "24/04/2009 00:00:00" ... correct
And to confirm, the ToString() method appears to output based on the Kind property.