Format JavaScript date as yyyy-mm-dd
You can do:
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
console.log(formatDate('Sun May 11,2014'));
How do I get a date in YYYY-MM-DD format?
Just use the built-in .toISOString()
method like so: toISOString().split('T')[0]
. Simple, clean and all in a single line.
var date = (new Date()).toISOString().split('T')[0];document.getElementById('date').innerHTML = date;
<div id="date"></div>
how to convert date in yyyy-MM-dd format of date type?
Convert it to java.sql.Date
:
Date obj = new Date();
java.sql.Date sqlDate = new java.sql.Date(obj.getTime());
System.out.println(sqlDate);
How to convert date format from dd/mm/yyyy to yyyy-mm-dd using carbon on Laravel
You can try this:
Carbon::createFromFormat('d/m/Y', $request->stockupdate)->format('Y-m-d')
Change date format from m/dd/yy to yyyy/MM/dd in Java
If you can use the java.time
API I would suggest something along the lines of the following:
String input = "7/20/21";
LocalDate receivedDate = LocalDate.parse(input, DateTimeFormatter.ofPattern("M/dd/yy"));
String formatted = receivedDate.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
// or if you actually need the date components
int year = receivedDate.getYear();
...
How to convert date in to yyyy-MM-dd Format?
Use this.
java.util.Date date = new Date("Sat Dec 01 00:00:00 GMT 2012");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String format = formatter.format(date);
System.out.println(format);
you will get the output as
2012-12-01
Related Topics
C# How to Check If a Url Exists/Is Valid
Read and Parse a Json File in C#
How to Dynamically Adjust Table Column Width in Rdlc Report
How to Check If a Socket Is Connected/Disconnected in C#
Using Recursion to Add Odd Numbers
Linq Multiple Group by in a List<T> Then Convert to List<T>
How to Get the Current Project Directory from C# Code When Creating a Custom Msbuild Task
How to Call a Button Click Event from Another Method
Deserialize Json in C# - How to Handle Null Return Values
Validate Indian Phone Number With Optional +91 or 0 Preceeding 10 Digits
How to Encrypt a Password Within Appsettings.Json for ASP.NET Core 2
Error Reading Jobject from Jsonreader. Current Jsonreader Item Is Not an Object: Startarray. Path
How to Convert Json Date to .Net Datetime During Deserialization
How to Set the Selected Item in a Combobox to Match My String Using C#
Make a File Open in Browser Instead of Downloading It