How to Convert Any Date Format to Yyyy-Mm-Dd

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



Leave a reply



Submit