Format date in Vaadin date picker - java

I'm using Vaadin Date picker 3.3.0
In Java, I set locale as the below code.
datePicker.setLocale(Locale.CANADA_FRENCH);
But the date format display is YYYY-MM-dd.
How to format it to: YYYY/MM/dd ??
Thank you!

The only way right now to influence the date format of the date picker by using the Java API is to use the locale (like you do).
There is a feature request for setting a date format manually (like datePicker.setDateFormat("YYYY/MM/dd");), maybe you want to give a thumb up on that feature request so that they will implement this soon: https://github.com/vaadin/vaadin-date-picker-flow/issues/156
Also in the comments of that feature request, there is described an alternative approach on how to set a date format manually by not using the Java API, but using JavaScript. Maybe you want to give it a try: https://github.com/vaadin/vaadin-date-picker-flow/issues/156#issuecomment-603904954

Related

How do i apply custom date formatting from excel in java?

I have an 2007 excel file called Test10. The first row has 10 headers, test1 test2 etc to test10. The second row, column 3 has a date, 10-10-2020 on the cell with the 10-10-2020 date there is a custom date format -> dd-mm-yyyy
The date in the cell is written as 2020-10-10.
I have the format from the cell in Java, however when I get it it's dd/-mm/-yyyy;# and the date is 2020-10-10.
I need to somehow apply that format to the date at hand.
I need something more flexible, is there a class that does that format? All I have managed to find so far is how to apply formatting to the excel in java when creating the excel, but not the other way around, when getting it from the Excel file.
I can manually serialize the format and remove the special characters that are not needed but that is a workaround.
I need a class that will apply the strange looking format to the date, in Java. Is there anything like that?
Also the example I provided above is a very simple example.
We're using a custom handler, the date comes as a double and we currently use DateUtil.getJavaDate to get the date as a string.
I have not created the handler so it's quite hard to understand the whole of it, but somewhere in the handler, the custom formatting for the cell is extracted from the excel and put into a variable, at the point where the DateUtil.getJavaDate is called I have access to the formatting variable.
Previously it was using SimpleDateFormat(CONSTANT_FORMAT).format(DateUtil.getJavaDate(d)) to format it, but I need to apply the custom format. Is there a library that parses xlsx date formats. As the dd/-mm/-yyyy;# format will not work with SimpleDateFormat.
Also I cannot serialize the format hardcoded as if I replace mm with MM how do I know if the user wanted minutes or months?
DataFormatter from org.apache.poi handles the weird excel formats

How and where to change date format of microba date picker

I am a beginner in Java programming and I am using Netbeans. I want to change the Date format of the Microba date picker to "dd-MMM-yy" and also remove the remaining fields. How to do these things?
Thank you.
Since Microba DataPicker is open source you could just clone the repo and have a look at the source code for your self.
If you have a look at the source code for the DatePicker class you will notice a number constructors which you can use to customise the picker, several take a DateFormat class which you can use to modify the format of the date value.
If you don't know how to use DateFormat, then I recommend you take a look at SimpleDateFormat, there are countless examples available to show you how to use it
As to remove elements, you'd have to look closer at the source code and make determinations on how best that might be achieved, since I'm not sure what fields you're talking about.

Date and Time picker for Tapestry 5.3.7 using Prototype

Tapestry comes with Date picker, which is fine if you want to pick dates only.
However, I'm in need of selecting time as well (date and time filtering).
Due to specific reason, I am not allowed to use jQuery, which is unforutunate, because I've found this neat Date and Time picker: https://fgelinas.com/code/timepicker/
Is there a similar, but Prototype based Date and Time picker for Tapestry 5.3?
Take a look at Howard's tapx-datefield library. I've not used it myself but it claims to support date & time. I think it wasn't included in tapestry core because of license incompatability.

How to input a date with a specific date format in struts 2.2.3.1?

I want to know if there is a way to force the input format for a date in struts, something like dd/MM/yyyy .
The date is written in a text field. I read that this is a locale sensitive subject, but it seems a too much to switch locales for a simple changing of format.
I know I could call addFieldError(fieldName, errorMessage) inside the method of my Action class but to me it feels like a date format should have been thought of to be configured in an Action-validation.xml file. I searched to configure this with properties file but found no working example.
Is using a custom StrutsTypeConverter and addFieldError(fieldName, errorMessage) the only way to do it? Or is there another version of struts in which the date format inputed in a text field can be specified?
UPDATE:
I assumed I made myself clear enough but some answers demostrate otherwise.
The use case is: User enters manually a date in an arbitrary format in a textfield, afterwards struts2 validates the date format as corresponding to the format set by the programmer or not, displaying a message accordingly.
A jQuery date picker with a <s:date> tag can be an alternative to what I want to achieve, but it it NOT what I asked. Furthermore, Javascript can be disabled, rendering the date picker useless, jQuery being a Javascript library as far as I understand it.
My action implemented ModelDriven but the date format can't be supplied anywhere to be forced in the text field, I did use my own validator, but I changed the mapping of the form element to be a String named in the action class, then used a validator with a SimpleDateFormat with the format retrieved from a resource bundle to convert it to a date, then formated the date again, to see if the representation is the same as the one inputed in the text field. Hardly after all that the format is clear. If there are other suggestions I welcome them, this seems like the only choice.
I find this drawback at the very least annoying.
If you want to have a specific format of date on your page, i will advise you to use struts 2 jquery datepicker. You can find a demo of this following this url. Go to widgets tab, select datepicker.

Using timezone 'EST' in freemarker template

<#setting time_zone="America/New_York">
Time: ${response.currentDate?string("MM/dd/yyyy hh:mm a zzz")}.
I need the timezone to be displayed as 'EST'.
But currently, when i run the application and the email gets generated from the template above, it is displaying as 'EDT'.
Can you please let me know what needs to be done to show as 'EST'?
The current timezone (on the system where I am testing) is Indian Standard Time
Thanks!
try <#setting time_zone="US/Eastern">
The behavior is expected at this point of year.
Refer: http://www.timeanddate.com/library/abbreviations/timezones/na/edt.html
(thanks to the above comment by Jon)

Categories

Resources