I am not sure if I am the only one having this issue on Chrome Browser but it is really annoying that I cannot fix it. I have done quite a bit of search here but nothing has helped.
First of all here is my ViewModel Data Annotation
[Required]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd hh:mm}")]
[DisplayName("Start Date")]
public DateTime? StartDate { get; set; }
On the view I am using datetimepicker bootstrap extension
When I am on the process of Creating the date I just select the date from the calander then I select the time as well. On the creating process there is no issue on Chrome and EI10. However, once the date has been created I go to edit mode to change the date. The date is displayed in dd/MM/yyy hh:mm format(example 18/03/2014 10:00) instead of yyyy-MM-dd hh:mm (2014-03-18 10:00). Without changing the date I click Update button on the page I get the validation error for the date fields.(See the screenshot) This is only in chrome browser. in EI10 everthing works fine. This is the first time that I am experiencing that something works on IE but not in Chrome :)
I have also set the datetimepicker date format to
$('.startdate').datetimepicker({ format: 'yyyy-MM-dd hh:mm' });
But still I cannot change the display format of the field to yyyy-MM-dd hh:mm. The last thing that comes in my mind that I will have to convert the format in the controler before it gets passed the view? But I thought the ViewModel annotations is actually should be doing that for me or I am wrong ?
I found a line of code that people are suggesting for the issue
jQuery.validator.methods["date"] = function (value, element) { return true; }
I still couldn't get it work
Related
I am working on an application whose target will be the greek market. My problem is that I want the date input fields to have the greek date format (which is dd-mm-yyyy) and the calendar to be in greek regardless of the browser settings. I suspect that there is some way to achieve this using the Locale attribute of either the Session, or the input field, in order to avoid using some 3rd party plugin (like the jQuery datepicker). Am I correct in thinking so? And if yes, what is the proper way to do this?
What I tried to do was setLocale("el") when initiating the input field and when creating a new session, both of which did not work out.
Override Application#newSession:
#Override
public Session newSession(Request request, Response response)
{
final Session session = super.newSession(request, response);
session.setLocale(yourFixedLocale);
return session;
}
We are trying to set default value of form field as current date in Jhipster.
Now, jhipster provides a moment format to a date which is eventually a ngbdatepicker. If we try to change the input type to "date" we cannot assign moment instance with date. If we typecast new date object as moment, the template shows error messages.
Please let us know if its possible.
Thanks in advance.
I have found a way around to solve this problem:
All you need to do is typecast your standard date object to moment after importing the moment obviously:
import * as moment from 'moment';
and typecast your field something like
your_form_field = moment(new Date());
Eg:
this.mstSite.siteUpdatedOn = moment(new Date());
Hope this solves your problems.
...Cheers...
In my application, a user can specify a date in a form, via a datepicker. Doing so, the date has this format : "2018-05-16T12:45:30Z".
Then, I want to store it in a MySql database, in a TIMESTAMP column.
Later, the user can edit his data. Consequently, the datepicker has to be initialized with the date coming from the server, previously saved.
To manage this, I created an accessor and a mutator :
public function setDateNameInputAttribute($value)
{
$this->attributes['date_name_input'] = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $value);
}
public function getDateNameInputAttribute($value)
{
return Carbon::parse($value)->format('Y-m-d\TH:i:s\Z');
}
This code works fine : my front-end reads UTC (Zulu) dates and I can insert timestamps in my database.
However, it's not perfect.
Let's say I need for whatever reason to add one hour to a stored date
$myObject = MyClass::find(1);
$theDate = $myObject->dateNameInput;
Now $theDate is a "T Z format" string, because of the accessor. I could recreate a Carbon object to do my addition, but I think this Carbon -> string -> Carbon transition would be ugly. How can I make a nice operation ?
If my applications contains a lot of input dates, with many different model names, is there a way to generalize my accessor and my mutator ?
Actually, is my first approach good ?
Thanks for reading !
Thanks to outsourced development, each row in many of my tables has an undocumented field called ts with values such as 1428881039. This is in addition to an actual created_at timestamp field with values such as 2015-04-12 17:23:59 MDT.
These values are passed to this function before displaying it on the web page:
public static function display($ts, $created_at, $format = self::FORMAT_DETAILS){
if ($ts && Session::has('tz_offset')){
$adminTzOffset = Session::get('tz_offset');
$final = (int)$ts - (int)$adminTzOffset;
return date($format, $final);
}else{
return $created_at;
}
}
I understand that it has something to do with possibly making sure that the date shown is for the user's correct timezone, but it doesn't even seem to work; it ends up showing the wrong time. Obviously I could just display the created_at timestamp, but I understand what this is trying to do here.
Any ideas of what this ts field represents?
Based on the info garnered from the comments, I would say that the ts field is an attempt to record UTC time - since it appears it is 6 hours ahead of your created_at field.
The code itself looks like it is using this $ts value to calculate a corrected timezone based off a session variable. If you're getting incorrect times, maybe the logged in user has an incorrect timezone setup?
I'm using Spring Roo on top of MySQL. I pull dates out via the Roo-generated JSON methods, make changes to that data in a browser form, and save it back via the Roo-generated JSON methods.
The date format I'm getting out is yyyy-MM-dd, standard MySQL date format. I'm using a calendaring widget on the browser to ensure the date I'm submitting is the same format.
Unfortunately my data doesn't go right through the ...FromJson() method, failing with the error:
Parsing date 2007-12-12 was not recognized as a date format
I presume that the problem is that it's coming out as a string, but JPA feels like it needs to generate a Date object to update.
I'll happily show my code about this, but it's nothing Roo didn't build for me.
It occurs to me that there's something it's referring to when it says "recognized as a date format". Is there somewhere I can change what date formats it knows?
EDIT: With #nowaq's help, here's the ultimate answer:
public static Lease fromJsonToLease(String json) {
return new JSONDeserializer<Lease>()
.use(null, Lease.class)
.use(Date.class, new DateFormatter("yyyy-MM-dd"))
.deserialize(json);
}
That way JSONDeserializer knows what class it's dealing with AND builds a formatter for all the dates in that class. Wicked!
Your question is very related to this one: Spring-roo REST JSON controllers mangle date fields Take a look and make sure you're using correct DateTrasformer(s) with your JSON deserializers. E.g.
new JSONDeserializer()
.use(Date.class, new DateTransformer("yyyy-MM-dd") )
.deserialize( people );