Is there any other way to get custom date in android except that java date picker
It means that you're trying to parse a date that doesn't match the pattern you choose. You should have a look at the simple date documentation to see which pattern you need: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
This link might help too: http://developer.android.com/reference/java/text/SimpleDateFormat.html
Related
Hello Devs,
I'm working on barcode scanner app, I get date and time at this pattern "20220610T230000Z"
I think its ISO8601 date-time format
However, I just want to parse this pattern so I can customize it as I want.
I tried this one:
val isoDate="20220610T230000Z" // from my barcode scanner
val df=SimpleDateFormat("yyyymmdd'T'HH:mm:ss.SSS'Z'")
val date= df.parse("20220610T230000Z")
but when i run code i get
java.text.parseexception unparseable
Thanks in advance
isoDate doesn't have any colons or periods in it. Since you're trying to turn isoDate into a Date object, you want something more like:
val df=SimpleDateFormat("yyyymmdd'T'HHmmssSSS'Z'")
Then, if you want to output a date String with different formatting, you'll have to create a different SimpleDateFormat instance (let's call it dt2) with the intended formatting, and call dt2.format(date). See here for a full example.
My issue solved
Thanks #OleV.V.
Solution
This pattern: "yyyyMMdd'T'HHmmss"
I am using CalenderView in android. I have a list of predefined dates as ["2019-02-15","2019-02-16","2019-02-17"]. When Calender is initialized and shown on Activity/fragment i want this dates to be selected.How to achieve this.
I am initializing calender this way
calender=v.findViewById(R.id.cal);
calender.setMinDate(System.currentTimeMillis()-1000);
How to achieve this ?
Looking into the Android API Reference you find this function:
CalendarView.setDate(long date)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone. https://developer.android.com/reference/android/widget/CalendarView.html#setDate(long)
So in your case you should call:
calender.setDate(long date);
In order to get the milliseconds, you should first parse your date string and then convert them to milliseconds.
Additionally I am not sure and I dont't think that it is possible to select more than one date at a time.
You cannot disable specific dates in the default CalendarView of android, for that you've to fork that widget and do your customisation. Then the other option is to use third party libraries like
material-calendarview
Using this library you can easily disable custom dates and apply custom background color and so on.
Material-Calendar-View
This is also other third party option which provides multiple date selection and so on.
I m developing android application. I need to convert datetime into date. I want to convert '25-07-2013 11:44AM' (datetime) into '25-07-2013' (date).
I am trying this function to convert SELECT date('25-07-2013 11:44AM'), but it was not working.Please suggest some solution for this problem.
According to this page, it does not seem that am/pm times are supported in date SQLite function (this should be noted as h or K according to the date format specification of Java at least; also it is explicitly mentioned %H hour: 00-24). Maybe experiment if using 24 hour clock will not trigger the issue.
I am not sure if you are search for Java code or SQL code , but if it is Java code then solution could be this :
String date = "25-07-2014 11:44AM";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
String newDate = dateFormat.format(dateFormat.parse(date));
System.out.println(newDate);
If in case your are looking for SQL code let me know I will share that as well.
The basic DatePicker at the Android Developers site http://developer.android.com/resources/tutorials/views/hello-datepicker.html appears to display in the format 4-26-2012. Can that formatting be changed to 04-26-2012? It appears to display M-d-yyyy but I need it to display MM-dd-yyyy so 01-01-2012 instead of 1-1-2012. Can the basic DatePicker be tweaked like this?
Hope so you where looking for this only.
To override the DatePicker format the best bet would be to override one of its constructors with a slight edit to the original code. You can edit the ViewGroup in code for you but I'd seriously consider not doing it that way.
Refer this Android: How to change the DatePicker view date format from MM/dd/yyyy to dd/MM/yyyy?
You know you can extract date, month, year, hour, minute and second and pad it and use it in any format you want. Just create a function. That's how I resolved the date issue when working on .NET web service, SQL Server and android.
I want to display a date picker for selecting date of birth,so as to user restricted to choose future date.currently date picker displays all dates including future also.i want to show the dates up to current dates only.
Thanks.
I recommend the Date Picker Dialog? Then just extend it to fit your requirements.
It's some what hard to explain how to create a Date Picker. What's better is looking at the sample code from the Android API Demos which shows you how to do a Date Picket and much more. You can figure out how to download these API Demos at: http://developer.android.com/resources/samples/get.html. Good luck!
Use the setMaxDate function, and set that to the current date
Datepicker dp = (DatePicker) v.findViewById(R.id.date_picker);
// Set it to only show past dates...
dp.setMaxDate(System.currentTimeMillis());
(reference)