How to display Date on a jsp page [duplicate] - spring-mvc

This question already has answers here:
Convert and format a Date in JSP
(6 answers)
Closed 2 years ago.
I'm making a website where customers can make reservations. Here I am going to save the reservation date to database. The date is saved in the database in "YYYY-MM-DD" format. (eg -: 2020-05-12)
The code in creating the column is startDate DATE
In my jsp page, I'm going to retrieve the reservation details as a list.
The code is as follows.
<core:forEach items="${pendingReservations}" var="reservation">
<tr>
<td>${reservation.startDate}</td>
</tr>
This code works perfectly fine except it shows the date in "YYYY-MM-DD HH:MM:SS" format. (eg -: 2020-05-12 00:00:00.0)
Here, I want to dispay the date in YYYY-MM-DD format. How can I do this?

add taglib
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
and try this
<fmt:formatDate value=${reservation.startDate} pattern="yyyy-MM-dd"/>

Related

moment.js get date format for input field placeholder [duplicate]

This question already has answers here:
Using moment.js, how to display the current date format for the user?
(2 answers)
Closed 5 years ago.
I am using moment.js within an application. When a user logs into the application their locale is set:
moment.locale(userLocale);
I want to add a placeholder to an input field that represents the date format expected, based on the user's locale:
<input type="text" placeholder="dd/mm/yyyy" />
Is there a way to get the string 'dd/mm/yyyy' from moment?
Try:
moment(new Date()).localeData().longDateFormat('L').toLowerCase()
You could access locale specific functionality through
var currentLocaleData = moment.localeData();
Then it is possible to get full format of abbreviated date-time formats using longDateFormat() method:
var format = currentLocaleData.longDateFormat('L');

<asp:ControlParamenter /> and nonstandard (en-US) DateTime binding

Database date format: "yyyy-MM-dd"
C# default date output: "MM/dd/yyyy"
My date format: "dd/MM/yyyy"
How do I use the asp:SqlDataSource with an asp:ControlParameter connected to an asp:TextBox using my date format? Specifically, I wanted to know
if there was a way to do this without having it done in code-behind
if I'm bound to code-behind, how to do it?
I've read about the Culture class, but I'm not sure that's the right path to explore. I've also had a check on some stackoverflow posts and came accross this Binding Date of DateTime in a control, but I've never seen this structure of Text formatting before in ASP.NET.
Thanks in advance,

Odd date formatting string error c#

I have a web application, and I have a label that is pulling a date from the db and displaying it. The date should be displayed "7/21/2011" but instead it is displaying as "July, 21 2011 12:00 AM"
I am formatting the string using the following eval statement -
<asp:Label runat="server" ID="lblDate" Text='<%#Eval("dtmAward", "{0:MM/dd/yyyy}")%>' />
What would make this date format in a long text date form, instead of a conventional date? Everywhere else I use that eval statement (with other dates from the db) it formats correctly.
This is just a hunch, but however you're binding the data, that column being specified as a DateTime type? If it's just specified as a string, I can imagine it doesn't get formatted.

ASP.NET Passing Inconsistent DateTime Format to SQL Server [duplicate]

This question already has answers here:
RDLC - "String Not Recognized As A Valid DateTime" Error
(2 answers)
Closed 2 years ago.
I know this is an age-old question but I'm not exactly new to it and I haven't found an answer which helps me so far!
I've got an ASP.NET site which displays data from an SQL Server 2005 database. At the top of the page are 'Date From' and 'Date To' textboxes which are used to filter the data shown beneath.
The data is displayed using an SqlDataSource, and the two dates are passed as parameters to a Stored Procedure. The textboxes display the dates and accept input in UK date format (dd/MM/yyyy) and it works fine.
Now I've added a new page with exactly the same setup, displaying slightly different data. In the backend I created a new Stored Procedure by copying and pasting my original one, it's almost identical. And yet on this page I get errors with my dates because they're being read as MM/dd/yyyy, meaning that today's date, for example, 15th August 2011, is passed as 15/08/2011 and isn't a valid date.
I've checked over everything and I can't understand why this should work on one page and not another, especially when I've basically just copied all of the original code and tweaked it slightly. Can anyone suggest anything I can check that I might not have thought of?
The text boxes are strings, which are in the thread local which is set from the browser (langauges).
Convert them to aa DateTime object first, using a local aware transformation, then write the dateTime object to the server. NEVER (!) deal with strings to sql server unless you format them in ISO independent form (2011-08-17 23:52:11).
But in general, ASp.NET will show dates, times, numbers in the local langauge of the browser. Either turn that off, or deal with it. It is nice for the user. So, check locales - user, server process. What is the thread current locale?
You need to use the SQL convert in stored procedure like:
convert(varchar, #yourdateParameter, 103) for format dd/mm/yyyy
or
convert(varchar, #yourdateParameter, 101) for format mm/dd/yyyy
Hope this helps.

Drupal CCK date field with just hours and minutes

How can I create a date field in Drupal just with hours and minutes without years and months?
You should be able to change the granularity when you create the cck field.
Jut select what you need from that Granularity options.
You can also just format the date by creating a new format:
Click on the date and time date format page and then create a new format that looks like this:
h:i
That's the time and date
Select that format for display.
You can go to the following site to see more Date format string options:
http://us3.php.net/manual/en/function.date.php
This should also help, http://drupal.org/node/134144#comment-1982750
how to add your own formats
set time only or set any php date setting you want

Resources