I have a Kendo UI grid that fetches data from API by AJAX call.
It has a column with date and the date is coming from backend in this format "2022-03-08T19:02:00".
This is one of the column of my grid where I am parsing the date :
{
field: "createdDate",
title: "Created Date",
template:"<div class='createdDateTemplate'>#= kendo.toString(kendo.parseDate(createdDate)) #</div>",
width: 150
}
I want to display this date in AEST or AEDT which ever is being followed . Is this possible from the template itself ?
EDIT :
I know that Kendo automatically renders date time in local format something like this for me:
GMT+1000 (Australian Eastern Standard Time)
But is it possible to display this time with +10 added to time itself ?
Edit: I am trying this
template:"<div class='createdDateTemplate'>#= kendo.toString(kendo.timezone.convert(kendo.parseDate(createdDate), 'Etc/UTC', 'Etc/GMT+10'), 'dd/MM/yyyy hh:mm tt') #</div>",
but I am getting this error:
Cannot read properties of null (reading 'getFullYear')
Kendo automatically converts the dates to the user's local time if you add zzz to the end of date , like this yyyy-MM-ddTHH:mm:sszzz.
One more thing , you say that your date is UTC but it doesn't have a Z (zero utc offset) at the end. Kendo won't add the offset without it , so I would recommend adding it.
Maybe you could try something like this:
#= kendo.toString(kendo.parseDate(modifiedDate+'Z','yyyy-MM-ddTHH:mm:sszzz'), 'dd/MM/yyyy hh:mm tt')#
Yes, you can display the date however you like it. Read the Kendo Date Parsing documentation. I would suggest though that the back-end send it in ISO format (e.g. yyyy-MM-ddTHH:mm:ss). So that on the front-end, you can just do parseDate without the need for additional parameters. Perhaps depending on the language setting of the browser it will be shown in AEST or AEDT format. If not, then you can do toString on the date.
Related
I'm probably blind to something right in front of me.
But In my MVC application, I have an object/model that has a DateTime property.
I do an AJAX GET to retrieve the model. The datetime when received looks something like Date(142342323).
I want to convert this date to the locale setting of the user. In moment.js I don't see a way to set it to local.
I thought about getting the currentculture in MVC and passing that as a value (and storing it as an hidden field on the page ) and then using that for the javascript date format...but there seems to be a discrepancy between c# formats and javascript formats.
Ideas anyone?
I mainly have 1 format for Europe and 1 for US (dd/mm/yyyy and mm/dd/yyyy).
How do I convert an anonymous date format to my own system culture info?
I am using a jquery calendar .datepicker(), but when I'm trying to get the value of that text box in the c# datetime variable, it shows invalid date time string. I have tried datetime.tryparse ,datetime.parse,convert.todatetime() and many others.
Now I am trying to get the date in jquery like var a = date.now();
But I am getting the following error: date.prototype //invalid date
I don't know why this is happening.
Reading your comments (" i am also getting error in prototype= invalid date and when i am trying to using this var a to set the date in another calendar"), I think you're trying to set calendars within jquery, possibly within an asp.net page.
If this is the case, you can set the date format when you create the datepicker :
$( ".calendar" ).datepicker({ dateFormat: "mm-dd-yyyy" }); // 10-25-2013
Format it as you need. For a list of date formatting options, see http://api.jqueryui.com/datepicker/#utility-formatDate.
If this doesn't help, it would be useful to know :
* what is emitting the date
* what is consuming the date (jquery/ C#)
* the actual code that is generating errors, if any.
After reading your responses, I think you should try specifying the format of your datepicker explicitly.
In my SQL Server I have this date format: dd-mm-yyyy, and I have some dates matches to this format. But when I use a datagridview in my application, it parses as mm-dd-yyyy but show dd-mm-yyyy. So if I have 05.12.2012 in my database, it thinks that 05 is month so it shows as 12.05.2012.
I have tried to use
Application.CurrentCulture = new CultureInfo("tr-TR");
but it did not work.
I should change the parsing format of my application, not showing format. How can I do that?
Thank you.
You should refer to the 'SET DATEFORMAT' command to set the format of the date. However, I think you problem lies somewhere else. You should be able to access the date column as a datetime value in c#. Usually data is passed in it's native format and so you should not have problems like the one you describe.
You can also send your date in the same date format in sql from your application.
Convert your date to sql format using the culture.
This works for me as we are using different culture in one application.
I'm having an issue with date/time formats in ASP.NET/C#. I have my SQL Server database set up with a PostDate field set to a type of "datetime". But it's saving the date in a strange format. I added a new row through a form and I got this as the date/time string:
2012-09-28 14:56:48.910
When it gets parsed by JSON.NET it gets even stranger. I get:
2012-09-28T14:56:48.91
The date and time are obviously correct, but how do I set things so that I can parse the date into a human-friendly way? There isn't really any code to post because the date is being added when the row is inserted. I'd like to format this as "Sept. 28, 2012 2:56 pm". How do I do that? Do I need to format the string before or after it's parsed as JSON?
That's not a "strange" format at all. The second form is ISO-8601; the first is ISO-8601 without the T. Considering the strange formats you can get in JSON, it looks like you've been let off pretty lightly!
Serialization formats aren't meant to be user-friendly, particularly - they're meant to be machine-to-machine formats.
I would hope that JSON.NET would give you a DateTime after parsing; it should only be giving you the ISO-8601 format after you've converted back to JSON.
If you've got a DateTime that you want to format for user consumption, there are all kinds of options with standard and custom format strings. Don't forget that you should respect the culture of the user, as far as possible - so make sure you're taking appropriate steps to either set the thread's current culture to be the user's one, or that you're passing the culture explicitly to DateTime.ToString etc.
You can try it in C#:
.ToString("MMM d yyyy, h:mm tt")
my type for date in the database is datetime and format of the datetime i am getting is 2/21/2011 12:00:00 AM .how can i convert this into 24 hour format.
Rather than changing the storage mechanism of the data in table, when you displaying the data, use the format you want and show it in your User Interface. Something like this:
DateTime.Parse(dateTime).ToString("MM/dd/yyyy HH:mm")
From the comments I would suggest that you may have a mis-understanding.
After you enter datetime data into a database, it's not stored as text, it's not stored as AM/PM or 24 hour, it's its own type. Only when an application converts it for display on screen does the difference materialise. This is an artefact of the application, not the database.
Are you able to eloborate on why this is an issue to you? How is the data being used?
- Are you going to be running any code?
- Are you copying it to Excell?
- Are you just basking in it's glory?