How does MVC pass datevalues to jQuery? - jquery-ui

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...

Related

How to get the date Format directives of a date string

I have a string in date format. It would be "2020-09-30", "09-30-2020", etc.
I would like to get back the Format directives of the date string.
For example, if the string is "2020-09-30", I would like to get back "%Y-%m-%d".
Check the below link by tweaking some the methods a bit you can get the desired result
https://railsexamples.com/ruby-date-formatting/

asp.net core html helper tag - set value (datetime) client side - format

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?

How save dd-mm-yyyy date format to mysql using grails

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()

XML Schema - Allow Invalid Dates

Hi I am using biztalk's FlatFile parser (using XML schema) to part a CSV file. The CSV File sometimes contains invalid date - 1/1/1900. Currently the schema validation for the flat file fails because of invalid date. Is there any setting that I can use to allow the date to be used?
I dont want to read the date as string. I might be forced to if there is no other way.
You could change it to a valid XML date time (e.g., 1900-01-00:00:00Z) using a custom pipeline component (see examples here). Or you can just treat it as a string in your schema and deal with converting it later in a map, in an orchestration, or in a downstream system.
Here is a a C# snippet that you could put into a scripting functoid inside a BizTalk map to convert the string to an xs:dateTime, though you'll need to do some more work if you want to handle the potential for bad input data:
public string ConvertStringDateToDateTime(string param1)
{
return DateTime.Parse(inputDate).ToString("s",System.Globalization.DateTimeFormatInfo.InvariantInfo);
}
Also see this blog post if you're looking to do that in multiple places in a single map.

How to format a date to JSON in Rails?

I need to produce a date in Rails which looks like this:
/Date(1294268400000)/
I have tried various combinations of DateTime, to_i, to_json but never managed to get the /Date()/ thing.
Do I have to simply get my date in ms and then wrap the /Date(and )/ manually, or is there a built in method?
What about (ruby 1.9.x)?:
Time.now.strftime("/Date(%s%L)/")
=> "/Date(1335280866211)/"
You should try
new Date(posixMillisecondsHere)
first. MDN says that calling the Date function outside of the constructor context (i.e., without the new) will always return a string containing a formatted date rather than a Date object.
Strictly speaking, when you do that, you are writing JavaScript and not JSON. JSON cannot contain Date objects.
RFC 4627 says
2.1. Values
A JSON value MUST be an object, array, number, or string, or one of
the following three literal names:
false null true
If you want to put a Date into what is strictly considered JSON and then get it back out, you must choose some way of using the JSON primitives (to wit, objects, arrays, numbers, strings, etc.) to encode a Date.
If you want to get a Date back out of JSON, whatever parses your JSON must understand the convention that you used to encode the Date.
Hope these are credible and/or official enough to help.
What about something like this:
in your config/en.yml file:
en:
time:
formats:
json: "/Date(%s%L)/"
and than in the view:
<%= l(Time.now, :format => :json) %>
Please note that you would need access to the helpers in the method that renders json. So it won't work if you are using ActiveRecord#to_json method for generating jsons.
Check out this question:
c# serialized JSON date to ruby
... simple answer seems to be to create a parse_date method.
It's the UNIX Epoch (seconds since 1970-01-01) right? What about using DateTime#strftime method?
# Taken from the Ruby documentation
seconds_since_1970 = your_date.strftime("%s")
UPDATE: OK, it's milliseconds, according to the documentation you can use your_date.strftime("%Q") to get the ms (but I've not tried yet).

Resources