I have a string date value of 3/2/2013 when using the Kendo DatePicker and Date(-62135578800000) from the when encoded to the array. I am binding a Kendo array to a template and would like the date to be user friendly, like "Sat, Mar 2". I have tried toString and ParseDate with no luck. I created a fiddle, http://jsfiddle.net/srakestraw/Q3MF8/, but can't figure out what I am doing wrong.
When I load the page, I get a date values like Date(-62135578800000) using Json.Encode, see below.
var viewModel = kendo.observable({
slots: #Html.Raw(Json.Encode(Model.Slots))
});
On the front-end, the user selects a date using the KendoUI datepicker and I push the value the the array. Am I using the wrong date format?
Thanks for any help.
The problem is that Date(-62135578800000) is not a valid JavaScript Date object:
alert(typeof Date(-62135578800000)); // string
Here is the updated jsfiddle: http://jsfiddle.net/Q3MF8/3/
This will format dates in a manner you can work with (ISO 8601) instead of those hideous Json.Encode formatter monstrosities.
#Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model))
Related
I am using laravel 5.0. I am getting data from controller as json. I am having value like this.
{"timstamp_date":"1434360957"},
I need to convert this unix timestamp value as Normal Date Like (15-06-2015) or (15-March-2015).
I have used Date(timstamp_date) but it is showing current time only. Not my timstamp date
You could use:
date("d-m-Y H:i:s", 1434360957);
EDIT
You could try;
var dateTime = new Date(1434360957*1000);
var formatted = dateTime.toGMTString();
https://jsfiddle.net/sp57Lnpf/
Use the date function. You need to specify the format as the first parameter:
date("d-m-Y", $timestamp_date)
http://php.net/manual/en/function.date.php
Laravel also comes with Carbon you could use that if you wanted to for further manipulation of the data if you so required it.
http://carbon.nesbot.com/docs/
Well, i decided to give it a try to Telerik MVC Extensions v.2012.2.607.340
I am having a problem with aggregating a decimal field in their grid.
I am using ajax binding.
I have an Action that returns a json
return Json(data);
data is nothing but a List. it converts into json without problems. My grid is showing the data but the aggregation is not working. returns 0 (zero).
i am following their examples here
I went to their forum/community but i couldn't find any solution to this. maybe they dropped the ball since they made it into Kendo something and they are charging a "grand" for it.
Anyone has had the same problem?
Thanks
You need to return something like this:
return Json(new {
Data = typeof(IEnumerable),
Total = typeof(int),
Aggregates = typeof(Dictionary<string, object>)
});
You need to precalculate Aggregates though. Key of a Dictionary is name of the field, and its value is calculated aggregate.
We have some data in a DataTable and we are using the query like this to get what we need.
IEnumerable<Results> subResult = from query in datatable.AsEnumerable()
select new Results
{
Name = query.Field<string>("Name"),
Date = query.Field<DateTime?>("Date")
}
This above query returns what i need but date in full format (Ex: m/dd/yyyy hh:min:sec am/pm) but we need only date part of it(only mm/dd/yyyy need to be pulled in). When looked in the properties of this, couldn't find an implicit way to get it, please help me in getting this result. Thanks.
The DateTime class has all the properties you just mentioned. You should try to fix your display with the ToString("anyformatyouwant") formats.
What about this?
Date = query.Field<DateTime?>("Date").Date
This will give you just the date part:
IEnumerable<Results> sub-result= from query in datatable.AsEnumerable()
where new Results
{
Name = query.Field<string>("Name"),
Date = query.Field<DateTime?>("Date").Date
}
However if you just want to display the date somewhere (meaning you're not using this to do date grouping, etc. then I would just specify the display format in your UI layer.
AFAIK there is no Date Class in .net, if you want pure date you should write a Class for that, otherwise you can pull out the part as a string
DateTime.Now.Date.ToString("yyyy/MM/dd")
gives you the current date in string type, but if you get the .Date part it gives you a DateTime object which still has a time part showing AM 12:00:00:0 blah blah
How can I validate the value of time using form validation engine? I'm using a timepicker (http://trentrichardson.com/examples/timepicker/) plugins to insert date and time in same field that gave a value of "2011-05-25 00:00:00" 00:00:00 is a default value if the user not tick on the slider.
time must not be in "00". Do i need to trim the value to validate it? I'm stuck with this. Please help.
jQuery.validator.addMethod('time', function(value, element) {
return this.value.search(/00:00:00$/) != -1;
}, 'Please enter a valid time.');
I have produced a data table. All the columns are sortable. It has a date in one column which I formatted dd/mm/yyyy hh:mm:ss . This is different from the default format as defined in the doco, but I should be able to define my own format for non-american formats. (See below)
The DataTable class provides a set of
built-in static functions to format
certain well-known types of data. In
your Column definition, if you set a
Column's formatter to
YAHOO.widget.DataTable.formatDate,
that function will render data of type
Date with the default syntax of
"MM/DD/YYYY". If you would like to
bypass a built-in formatter in favor
of your own, you can point a Column's
formatter to a custom function that
you define.
The table is generated from HTML Markup, so the data is held within "" tags.
This gives me some more clues about compatible string dates for javascript:
In general, the RecordSet expects to
hold data in native JavaScript types.
For instance, a date is expected to be
a JavaScript Date instance, not a
string like "4/26/2005" in order to
sort properly. Converting data types
as data comes into your RecordSet is
enabled through the parser property in
the fields array of your DataSource's
responseSchema
I suspect that the I'm missing something in the date format. So what is an acceptable string date for javascript, that Yui dataTable will recognise, given that I want format it as "dd/mm/yyyy hh:mm:ss" ?
Define your locale
YAHOO.util.DateLocale["pt-BR"] = YAHOO.lang.merge(YAHOO.util.DateLocale, {
x:"%d/%m/%Y"
});
And your column settings as follows
{key:"columnKey", label:"columnLabel",
formatter:function(container, record, column, data) {
container.innerHTML = YAHOO.util.Date.format(data, {format:"%x"}, "pt-BR");
}
}
Javascript is able to construct a Date using a datestring in the following format:
new Date("April 22, 2010 14:15:23");
If you don't have control of the format of the datestring on the server-side (or don't want to change it) write a custom parsing function that takes the datestring and returns a newly constructed Date object.
You could either use this parser function when constructing the data represented in your DataTable.
rows:[{name:"John",born:customParser("[date string here"]},
{name:"Bill",born:customParser("[date string here"]}
]
-OR-
If you are using Yui's DataSource module (as indicated by your second grey box), you can register this parser function on the date field so that it will already be a Date() before the DataTable is constructed.
dataSource.responseSchema = {
. . .
fields: [
...
{ key: "birth_dt", parser: customParser }
...
]
....
}
You can pass dates from server to client in any format you wish, just in DataSource.responseSchema.fields set parser field to a function that will parse it. Look for stringToDate in dynamic data example.
On client side, you can display Dates in any other format, providing function in formatter field in respective ColumnDefs.
In order to set whole DataTable's date format, set its dateOptions option; alternatively, you can set ColumnDef.dateOptions, all same as described in YAHOO.util.Date.format() docs for oConfig parameter.
For current locale and whole DataTable, it should be
var myConfigs = {
initialRequest: ...
...
// http://developer.yahoo.com/yui/docs/YAHOO.util.Date.html
dateOptions: {format: '%c'}
};
You can also set sLocale there.