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

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');

Related

How to change date format in Email Template of Dynamics365?

I want to get the date in this format -
MM-dd-yy.
For example: 10-12-23
I'm writing this code but don't getting the desired solution -
{<entity_name>:<attribute>/#date;} Check-In Link
What should I write in the date part?
I'm afraid the only way to make it work is to set the user's locale to a locale that uses MM-dd-yy format.
Alternatively, it's possible to create a custom string field, populate that field with a properly formatted date and use the value of it in your template.

How to display Date on a jsp page [duplicate]

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"/>

How to change the date format in WordPress contact form 7

I am using the wordpress contact form and its field date picker, its default is DD/MM/YYYY, but I want to change its format to MM/DD/YYYY.
Can any one tell me how to do it in contact form 7.
Regards
If above writen code is not working its means:
If a value is specified in a date field, the value must be in YYYY-MM-DD format (e.g. 2013-04-08) according to the HTML5 specification.
This is in most cases you don’t need to care about because browser’s date picker UI will set a value in the correct format.
I changed the display date format to mm/dd/yy in the front end of my form by using plugin Custom Datepicker NMR for Contact Form 7.
This allows you to use a new input field in your contact form called [datepicker ]
Install/activate the plugin and specify format date to show in the web browser like this:
[datepicker myFirstDatepicker id:myFirstDatepicker format:mm/dd/yy]
This plugin uses jquery-ui datepicker.
Copy and paste it in your function file and also you can modify the date format as per requirement.
add_filter('avf_datepicker_dateformat', 'avf_change_datepicker_format');
function avf_change_datepicker_format($date_format) {
$date_format = 'mm / dd / yy';
return $date_format;
}

Sharepoint 2013: How to change date format of DateTime textbox in NewForm/EditForm?

I have a DateTime Field "Date1" in my list. I need to set its format as "DD-MMM-YYYY" (eg: 29-Mar-2017). I achieved doing this on Display form using the FormatDatetime function in XSL:Select.
I need to change it on New/Edit forms too, when date is selected from datepicker
As far as I know, this is not possible by using "Calculated Value" property of
"Date1" column as self referral is not allowed.
What you can do is create a new "Calculated" column and then use formula =TEXT(Date1,"dd MMM yyyy"). Select "Date and Time" in data type returned and use "Date only" in format.
This will solve your purpose

Formatting th:field in Thymeleaf

I have a form input field in Thymeleaf. The field (bookingEntry.datefrom in the code snippet below) is type Date. I use a datepicker to allow the user to select and format the required date to enter the field. This is all fine.
However, I want the initial value of the date (which I have set to the current date) to be displayed in the format that I choose. So, how do I format the date initially shown in a th:field. th:value is ignored (Thymeleaf is getting the value from the backing object, as it should) and I can't seem to apply a format to the th:field.
Thymeleaf code is:
<input type="text" class="form-control getdate"
th:field="*{datefrom}" placeholder="Date From"
th:value="${#dates.format(bookingEntry.datefrom, 'dd-MMM-yyyy')}"/>
I'm sure that I could use a String which is initialise in any format that I choose, rather than a Date type, but I wondered if there was a way to format initial values in a th:field?
Many thanks
I missed the simple answer, simply because of my limited knowledge of Spring. I'm adding it here incase it helps any other novices like me.
The #DateTimeFormat annotation on the element in the object being passed to the form does the job. It ensures that the Date object is formatted in the way that you wish (irrespective of whether you are using Thymeleaf or not).
In the example above, within the bookingEntry object
#Temporal(DATE)
#DateTimeFormat (pattern="dd-MMM-YYYY")
private Date datefrom;
In case your date is null, it will give you error. We have to check the value before we parse the date.
<input type="text" name="date"
th:value="${user.dateOfBirth}?${#dates.format(user.dateOfBirth, 'dd-MM-yyyy')}:''"
placeholder="dd-mm-yyyy" id="pickyDate"/>

Resources