match datetime pattern with spring DatetimeFormat annotation - spring-mvc

I'm trying to use this jquery input mask plugin to submit a date time field.
The input is being submitted as:
081220151530 - which is 3:30pm 08/12/2015
or in am/pm it's submitting
081220150330p
I'm trying to bind that value to a Joda DateTime field and I think I should be able to specify a custom pattern on the field annotation.
But this pattern's not matching and throwing a validation fault:
#org.springframework.format.annotation.DateTimeFormat(pattern = "DDMMYYYYhhmm")
private DateTime followUp;
The error:
Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'followUp'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type #javax.persistence.Basic #org.hibernate.annotations.Type #org.springframework.format.annotation.DateTimeFormat org.joda.time.DateTime for value '081220151230'; nested exception is org.joda.time.IllegalFieldValueException: Cannot parse "081220151230": Value 22 for monthOfYear must be in the range [1,12]
So 2 questions:
1. Ideally, it could parse the am/pm value, so is there a pattern that will match the am/pm style?
If not, what's the right pattern string to match the 24 hour version?
Update to original question:
So I figured out the 24H pattern, using the DateFormat pattern ddMMyyyyHHmm
But the second part I can't get - so I'm going to reassign this to the jquery-inputmask tag because the fact that it's submitting the am/pm as a and p respectively maybe a bug....
So I think I can solve this if someone knows how to make it submit pm/am instead?

try: ddMMyyyyHHmma
post the value like 05052016

Related

Mule datamapper DateTime conversion gives unparsable date for String 'yyyy-MM-dd'T'HH:mm:ss.SSSZ'

I have a request xml having a dateTime string as '2014-09-23T00:00:00.000+01:00' and I am mapping it to an element of type xs:dateTime using Mule 3.5 datamapper.
The Datamapper internally applies str2Calendar(Str,Str) function or mapping.
So I edited the script to look like:
output.dateAndTimeString = str2calendar(input.dateAndTime, "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
The error in log is:
java.text.ParseException: Unparseable date "2014-09-23T00:00:00.000+01:00"
Is anything wrong with Mule data-mapper or with my conversion technique?
You can drop the 'Z' and use the overloaded str2calendar to set the default timezone. This example uses the MEL expression to get the servers timezone:
output.dateAndTimeString = str2calendar(input.dateAndTime, "yyyy-MM-dd'T'HH:mm:ss.SSS", server.timeZone);

How can i Convert the DatePicker Input to string

I am using the following Codes to get the date from the date picker
objDD_ml.EffDate=(DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput).ToString
But it does not return the date... It returns like 'DateInput'
How can i use the code to get the value for Effdate as a correct format of date
Anyone please help me..
Whenever you want date into string and in specific format you can always apply following :
objDD_ml.EffDate = (
DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput
).ToString("dd/MM/yyyy")
Try to cast the FindControl object into the corresponding ASP control externally. Then access the value of that control and convert it to .ToString
I don't know what control you are using, but it should be something like below -
objDD_ml.EffDate = ((RadDatePicker)(drv.Cells[i].FindControl("rdpEffDate")).SelectedDate.Tostring;

Error converting date for Calendar in asp.net

I have written code for two checkboxes:
string sdate= Convert.ToDateTime(txtFromDate.Value);
string edate=Convert.ToDateTime(txtEndDate.Value);
I am getting the following error: "String was not recognized as a valid DateTime".
Well, it's reasonably clear: the input string wasn't in an appropriate format. I suggest that instead of using Convert.ToDateTime, you use DateTime.TryParseExact and specify the format string (or strings) that you expect the user to enter.
Using TryParseExact instead of just ParseExact means you can detect if the user has entered an incorrect date without an exception being thrown - and you should check for that. Basically the return value of TryParseExact indicates success or failure, and an out parameter is used to capture the parsed date/time on success.
What I hadn't noticed to start with is that you're then trying to assign a DateTime value to a string. That's not going to work - but we can't advise you on what you should be doing instead without knowing what you want to do with the data. I suspect you want to change sdate and edate to be DateTime variables instead.

Parse string pattern into Date in Flex

Is there some way in flex to parse strings to date. I want it to support custom formats similar to 'dateformatter'. Using 'dateformatter' class we can parse date object in various string formats as specified by 'formatString property'. I want it other way round, from string to date. The parse method 'Date.parse(my_string)' does string parsing but for a very limited set of formats. Can't we have something similar to following, where user can specify his/her own formats.
someformatter.formatString = 'HH::MM::SS' ;
mydate = someformatter.formatTodate('23::56:34');
Will 'parseDateString' method of dateformatter be useul here?
Thanks in advance.
You can use
DateField.StringToDate()
This is static function of DateField class, and returns Date object.

ognl.MethodFailedException "setCreatedDate" failed for object com.security.data.PasswordHistory#d5b561

i am using strut2.1.6 with tomcat 5.5
i have a Date field createDate in my PasswordHistory Bean, and corresponding date component on my "search.jsp" this field is optional - no validation required .
if i submit the form i am get the follwoing error on console
ognl.MethodFailedException: Method "setCreatedDate" failed for object com.security.data.PasswordHistory#d5b561 [java.lang.NoSuchMethodException: setCreatedDate([Ljava.lang.String;)] –
it looks that it is trying to convert the empty string to date, when it fails it tries to search the corresponding String argument method and if it converts the value to date successfully it calls the corresponding Date argument method – Muhammad Shahid
i want to avoid any conversion if the field is emtpy.
Do you have struts.devMode = true in struts.xml? From the docs:
And thirdly, perhaps the setting which is less widely known, and therefore a source of much confusion: it will raise the level of debug or normally ignorable problems to errors. For example: when you submit a field which cannot be set on an action 'someUnknownField', it will normally be ignored. However, when you're in development mode, an exception will be thrown, telling you an invalid field was submitted. This is very useful for debugging or testing large forms, but can also be confusing if you're relying on parameters in your request that are not set on the action, but which you are using directly in your view layer (warning: bad practice, you should always validate input from the web).
http://struts.apache.org/2.1.6/docs/devmode.html

Resources