In my grails application i use a javascript calendar plugin which accepts date in dd-mm-yyyy format. I converted the date into yyyy-MM-dd HH:mm:ss z before saving to database which is the default date format in grails. But still it gives me an error of Invalid date format. I tried changing the
default.date.format in messages.properties file. But still it not works. How can i save the dd-mm-yyy format to Mysql using grails?
try using the binding annotation on your domain class
import org.grails.databinding.BindingFormat
...
class MyClass{
#BindingFormat('dd-mm-yyyy hh:mm a')
Date dummydate
}
in the #BindingFormat annotation you can put the format you use client side.
You can also do
Date.parse("dd-MM-yyyy HH:mm:ss", params.date)
In case you want to save it to database without time we can do
Date.parse("dd-MM-yyyy", params.date).clearTime()
Related
in my json i've this date generated by JsonConvert.SerializeObject()
2020-05-11T15:27:50.3666678+02:00
I get this json by jquery ajax call and i need to set this value (client-side) to an html helper tag
to set this field client-side i do:
$("#scandate").val(details.ScanDate);
where scandate contains the date in the format above 2020-05-11T15:27:50.3666678+02:00
but i got this error:
The specified value "2020-05-11T14:41:59.5753508+02:00" does not conform to the required format. The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS".
trying to pass a (fixed) date like this 2020-05-11T15:27:50 the component shows the date!
how can i adjust it avoiding to do a brutal subtring in order remove the last part of the date?
In a web application the user can choose the timezone which is passed to the timezone attribute of the calendar widget:
<p:calendar value="#{curValue}" timeZone="#{settingsBL.getTimeZoneIdSet()}" />
The delivered date in the backing bean is converted to the timezone of the server (JBoss in my case with CEST). The backend want the date and time as always as UTC (and delivers it in UTC).
So when I store a date I have to convert the CEST date to UTC and save it. If a date is delivered from backend it is UTC. I have to convert it to the system default (JBoss with CEST) and the calendar will take care that it is displayed correctly on the client.
Is this correct? I am a little bit confused about that. The server timezone is variable and cannot be set hard to UTC or something.
The date from the client is always converted to CEST for my example. Regardless what I set to javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE in web.xml.
I am using primefaces 5.2.13 and Mojarra 2.2.12 with JBoss 6.4
The timeZone attribute of any java.util.Date based JSF component which allows manipulating the time part must be set to the one as expected by the view (frontend). It will be used when converting the java.util.Date instance from the model (backend) to the String representation which will be embedded in generated HTML output. It will also be used when converting the incoming String request parameter value to a concrete java.util.Date instance which will be used in the model. If you don't allow manipulating the time part, then just stick to the default of timeZone="GMT".
And now comes the key: the java.util.Date does not hold any timezone information. It's internally always GMT. JSF knows that. JDBC knows that. JPA knows that. As long as you tell JSF what timezone the view uses, and you tell JDBC/JPA what timezone the DB uses, then all should be well.
Perhaps your confusion is caused because you did something like System.out.println(date) to verify one and other. Its toString() result will internally use TimeZone#getDefault() and thus not explicitly use GMT/UTC during the String generation. You'll then confusingly see the date in the system default timezone being printed. To print the date with GMT timezone (in order to debug/log/verify it and such), do so:
System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(date.toInstant().atZone(ZoneId.of("GMT"))));
I am trying to implement the DateRange extension into a MVC site.
The site is trying to use this date format: yyyy/mm/dd (ie 2011/02/14).
When I try a 'Create New' on a page the jquery-ui.js throws an unhandled error on the parseDate function. The parseDate functions shows 'm/d/yy' as the format and '2011/02/09' as the date value.
What is confusing me is how after changing all the m/d/yy formats to yy/mm/dd in the code that there is still the other format showing.
After constant tweaking the sample the only thing that appears to influence the date format is the 'Date.cshtml' file. Changing this files format string will influence how the initial(default) date-time values show. Changing the other C#/JS files seems to have no influence on how the datepicker displays the dateformat.
As a result of this I will be dropping this extension from my project...
Hi
In my application the user can selects a date in a "dd/mm/yyyy" format from a calendar and save it to a date field in the database (mySql).
Everything is going ok on my local server (in Israel) but on my host server ( in the US) it fails.
I did some checking in the console and found that
in my local computer(Israel) when I do the following:
d=Date.new
d.reported_date="23/01/2011",br>
d.save
I get
=>true.
In my host server(US) when I do the following:
d=Date.new
d.reported_date="23/01/2011"
d.save
I get
=>false
When I did this check with another date for example "04/01/2011"
the local and the host could save the record.
So I concluded that it seems like the host(in US) can receive date only in "mm/dd/yyyy" format and convert it to mySql date format
and the local computer(in Israel) can received date only in "dd/mm/yyyy" format and convert it to mySql date format.
(Both in the server and in my local machine the format in the mySql server is yyyy-mm-dd)
I need to find a solution which can adjust mySql in my local machine to behave like in the host server.
I will be glad to some advise
Thanks
Try using yyyy-mm-dd instead, that can never be read wrong and all databases I have worked with accepts that format.
try to use puts DateTime.strptime(inputStr, "%Y-%m-%d_%H-%M-%S")
I'm POSTing json data to a Grails controller which I then parse using JSON.parse.
It all works fine except for date fields. I don't believe there is an explicit syntax in json to represent a Date but I've tried a number of formats with no luck. Can anyone tell me what format I should use so that the grails JSON parser can create a Date object.
There isn't a specific format, but you can define your own. For example, these guys here are adding a '#' to the beginning and the end of the string.
According to Grails docs here, you can define:
grails.converters.json.date (String) - Configure how Date values
are serialized to JSON
"default" - String representation according to the JSON specification
"javascript" - new Date(...)
Update: It appears that there is no mapping to Java Date objects. If you know the fields that are dates, you can parse them into Dates