set date default ion-datetime Ionic v-2 - ionic-framework

I have problem i try set the default date is today end disable day passed.
But when i set the default date is today i must convert date to string. So i can't calculator this.
Some body help me set the default date is today and calculator date. Thanks for reading my topic!
This is my code:
this.startDate = new Date().toISOString();
this.minDate = new Date().toISOString();
<ion-datetime
displayFormat="MMM DD, YYYY HH:mm"
[min]="minDate"
[(ngModel)]="startDate"
>
</ion-datetime>

From ionicv2 docs
https://ionicframework.com/docs/api/components/datetime/DateTime/
Ionic uses the ISO 8601 datetime format for its value. The value is
simply a string, rather than using JavaScript's Date object.
Additionally, when using the ISO datetime format, it makes it easier
to serialize and pass within JSON objects, and sending databases a
standardized format which it can be easily parsed if need be.
So, you can get the ISO string date by
startDate: String = new Date().toISOString();
and use it in the view like so
<ion-datetime
displayFormat="MMM DD, YYYY HH:mm"
[(ngModel)]="startDate"
>
If you want to disable backdated date, you can try this
min="2016-10-31"
and also you can specify the maxDate by
max="2020-12-12"
in your ion-datetime directive

Related

talend format yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss

I am trying to change the date format in txmlmap component but its not working
i want change date format
from yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss
expected output:- yyyy-mm-dd HH:mm:ss
You can parse your string to a date using your source pattern and then format that date to a string using your target pattern:
TalendDate.formatDate("yyyy-mm-dd HH:mm:ss", TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ss.SSSz", myDateString))
In almost all coding languages format is text, while date is a double. That means you must first make a date of the first expression, before setting the new format of that date. But in Your case the 'T' is some kind of special format that need to be replaced with a blanck space. I have no idea about what it would look like in talend but in VB it would look like this:
' from yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss
DateTxt = "2022-12-01'T'22:45:10"
DateTxt = Replace(DateTxt, "'T'", " ")
MyDate = CDate(DateTxt)
MsgBox Format(MyDate, "yyyy-mm-dd HH:mm:ss")

Convert the String Monday 5 October to date using Google Apps Script

I need to convert the date string of type WEEKDAY DATE MONTHNAME, Example: from "Monday 5 October" to date object.
I have tried with
Utilities.formatDate(new Date("Monday 5 October"), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'")
How do I convert it, I am ok using V8 apps script engine
The Date constructor accepts timestamp strings formatted according to IETF-compliant RFC 2822 timestamps and ISO8601.
There are many ways to convert your string to date, but probably one of the simplest is appending the current year to your string, using getFullYear():
const source = "Monday 5 October";
const date = new Date(`${source} ${new Date().getFullYear()}`);
Reference:
Date() constructor
IETF-compliant RFC 2822 timestamps

Java 8 LocalDateTime has different results

I am trying to update some code to use Java 8's feature for parsing multiple date formats. my local time on my box is set to UTC-11.
the below code works when using the SimpleDateformat.
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date correctDate = dateFormat.parse("2018-09-6T03:28:59.039-04:00");
//Gives me correct date
System.println( correctDate);//Wed Sep 5th 20:28:59 GMT-11:00 2018
I am trying to update this code to give the same date as above with the DateTimeFormatter in Java 8 , so i can handle another date format..
DateTimeFormattter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]XXX");
LocalDateTime updateDate = LocalDateTime.parse( "2018-09-6T03:28:59.039-04:00", dtf);
//shows the wrong date of 2018-09-06 03:28:59.039.
System.out.println( updateDate.toString() );// 2018-09-06 03:28:59.039
[solved]
I was able to fix this by using ZonedDateTime.
ZonedDateTime zdt = ZonedDateTime.parse("2018-09-6T03:28:59.039-04:00");
zonedDateTime = zdt.withZoneSameInstance(ZoneId.of("GMT"));
Date correctDate = Date.from( zonedDateTime.toInstance());
//correctDate is what i wanted Wed Sep 5th 20:28:59 GMT-11:00 2018
As soon as you parse your date string into a LocalDateTime the zone offset is lost because LocalDateTime does not hold any time zone or offset information.
When you format the LocalDateTime to a string again, you'll only have the time as it was parsed without offset.
The Documentation of LocalDateTime clearly explains this:
This class does not store or represent a time-zone. Instead, it is a description of the date, as used for birthdays, combined with the local time as seen on a wall clock. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.
You should consider using OffsetDateTime or ZonedDateTime.
Solved, using OffsetDateTime as suggested in the accepted 'Answer':
OffsetDateTime odt = OffsetDateTime.parse("2018-09-6T03:28:59.039-04:00");
Date correctDate = Date.from( odt.toInstant());

Swift: Get correct time zone from Date Picker?

I am trying to get the correct time zone from the date picker in swift using time formatter, it's not working. I'm getting UTC, not EST.
1) If I print dateFormatter.stringFromDate(datePicker) I get EST, but
2) I don't need a string, I need an NSDate in EST so
3) I can use it to get the timeIntervalSinceDate(NSDate) in EST.
My trick of trying to take it from string back to NSDate as seen below didn't work. It's still in UTC and the time interval since date is not right.
dateFormatter.locale = NSLocale.currentLocale()
dateFormatter.timeZone = NSTimeZone.localTimeZone()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let date: NSDate = dateFormatter.dateFromString(dateFormatter.stringFromDate(datePicker))!
print(date)
print(date.timeIntervalSinceDate(datePicker))
The above answer is totally wrong. Date picker report the date in system locale anytime, so, if the datePicker shows an 08:00 Time and you are GMT+2, the property date of the picker will be 06:00.
So for have the absolute value of the datePicker you have to pass to him the UTC time zone in view did load with:
datePicker.timeZone = TimeZone.init(identifier: "UTC")
Now, the date property of the picker will be the expected and choosen one.
You cannot "get a time zone" from a date picker. You can just get a date. The date will be independent on the current time zone of the device.
Perhaps you think you have a different date, but actually, there is no such thing as a "UTC date" or "EST date". Instead, there is only one date, and you use date formatters to display them for various time zones.
Note that there is quite a bit of redundancy in your code. The default locale and time zone of a date formatter are already the same values that you set. Also, when you have a method that returns a NSDate you do not have annotate the constant with : NSDate, making your code more verbose and cluttered.
Note that if you print a date the console will always show UTC. e.g.
let date = NSDate() // Nov 10, 9:44 PM
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd hh:mm a"
let dateString = dateFormatter.stringFromDate(date) // "2015-11-10 09:44 PM"
print(date) // "2015-11-10 20:44:54 +0000\n"
To set the TimeZone of a DatePicker to UTC use:
datePicker.timeZone = TimeZone.init(identifier: "UTC")
Notice the camelcase notation of "timeZone".
Unfortunately I don't have enough credit to comment on the last post, which has it almost right, so I had to create a new answer.
A little trivia: TimeZone has been around since iOS 2.0 as is stated here:
https://developer.apple.com/documentation/uikit/uidatepicker/1615976-timezone
Those who are trying to find a solution and are not able to wrap their head around the exact issue. Here is what something I tried:
Use time.addTimeInterval(-14400) function, where -14400 is the 4 hours difference. So if you want UTC to EST do this.
Something like this:-
var time = Date() // assuming you have this in UTC
time.addTimeInterval(-14400)
You can also use addingTimeInterval function which returns you the new date.
I know this is a little wonky cause we're manually doing this, but hope it helps someone.

How to set client specific timezone and date

pardon me if it seems to be a duplicate question.
I have seen many posts already on this topic. However after trying many examples could not find the solution to my problem.
I tried this code
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy", Locale.ENGLISH )
Date newDate = sdf.parse(sdf.format( new Date( dateTimeString ) ) )
However the second line of code always converts the date to the server specific date and timezone which i don't want. I also tried the following
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zzz", Locale.ENGLISH )
log.info "+++++++++++++++++hidden date ++++++++ " + params.hiddenGameDateTime.substring(35, 38)
log.info "x = " + sdf.format( new Date ( params.hiddenGameDateTime ))
String tzone = params.hiddenGameDateTime.substring(35, 38)
sdf.setTimeZone( TimeZone.getTimeZone( tzone ) )
log.info "Timezone = " + sdf.getTimeZone().getDisplayName()
Please note that
sdf.format( new Date( dateTimeString ) )
gives me the desired result, however it gives me the string value of the date and the actual value to be stored in database is of the Data type date which can't hold the string value.
the value for date and time in my case gets converted to PST date and time. how can i avoid this. The user input date with timezone should be stored in the database as it is with no change in date and timezone.
An observation: The constructor new Date( dateTimeString ) is deprecated. A better replacement would be something like that:
SimpleDateFormat sdfOriginal = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date d = sdfOriginal.parse(dateTimeString);
Furthermore: An expression like sdf.parse(sdf.format(...)) using the same format object does not make much sense.
But most important, your statement "the second line of code always converts the date to the server specific date and timezone" seems to be based on test output like:
System.out.println(newDate);
This implicitly uses toString() which is based on jvm default time zone, in your case the server time zone. But keep in mind, the internal state of j.u.Date does not reference any time zone. A Date is just a container for a long, namely the seconds since 1970-01-01T00:00:00Z in UTC time zone, that is a global time.
Additional remark:
If you need the client time zone (in a scenario with multiple users in different time zones) to create user-specific formatted date strings, then you indeed need to store the time zone preference of every user in the database, so you can use this information for output in an expression like:
SimpleDateFormat sdf = new SimpleDateFormat("{pattern}";
sdf.setTimeZone(TimeZone.getTimeZone("{user-preference-time-zone}");
String userOutput = sdf.format(date);
Date is always jvm timezone specific. You need to normalize it to standard time and store it in DB to cater with different timezone servers.