How to format current date into yyyy-mm-dd in Java

Ads
 

How to format current date into yyyy-mm-dd in Java

Hi,

I have requirement to format the date into yyyy-MM-dd format for inserting it into MySQL database.I am searching code formatting the current date into this format. I have to do this in Java Programming Language.

How to format current date into yyyy-mm-dd in Java?

Thanks

View Answers

September 13, 2020 at 6:31 AM

Hi,

Following sample code will help you in getting the formatted date:

package net.roseindia;

import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date;

public class CurrentDateFormat {

public static void main(String[] args) {
    try {
        DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        Date currentDate = new java.util.Date();//Current date
        String sDate = fmt.format(currentDate);
        System.out.println("Formatted Current Date:" + sDate);
    } catch (Exception e) {
        System.out.println("Exception :" + e);
    }
}

}

The code:

DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");

formats the date into yyyy-MM-dd format. the MM is used for getting the month part of the date.

Thanks


September 13, 2020 at 6:33 AM

Hi,

Check all the date formatting options at:

Thanks


September 13, 2020 at 7:25 PM

Hi,

Here is the output of the program in Eclipse IDE:

Thanks

Ads









Related Tutorials/Questions & Answers:
How to format current date into yyyy-mm-dd in Java
How to format current date into yyyy-mm-dd in Java  Hi, I have requirement to format the date into yyyy-MM-dd format for inserting it into MySQL... to do this in Java Programming Language. How to format current date
How to convert date to string in Java in yyyy-mm-dd format
to String in yyyy-mm-dd format. How to convert date to string in Java in yyyy...How to convert date to string in Java in yyyy-mm-dd format  Hi, I... it to yyyy-mm-dd String format. Here is Java example for converting String Date
Advertisements
How to convert string to date in java in yyyy-mm-dd format?
How to convert string to date in java in yyyy-mm-dd format?  Hi, I have a date in yyyy-mm-dd format. How to convert string to date in java in yyyy... java.util.Date; /* * Example of formatting date in Java * from yyyy-mm-dd formaat
get current date in java in yyyy mm dd hh mm ss format
get current date in java in yyyy mm dd hh mm ss format  Hi, I want to get the current date into string yyyy mm dd hh mm ss format. How to get current date in java in yyyy mm dd hh mm ss format in a Java program? Thanks  
how to format date from yyyy-mm-dd to dd-mm-yyyy
how to format date from yyyy-mm-dd to dd-mm-yyyy  <!DOCTYPE html... to calculate the nos. of days between two dates, the date format is in "yyyy-mm-dd", so what i want is in "dd-mm-yyyy" format. So, how to change it? I would be much
validationrule for date as format yyyy-mm-dd in drools
format yyyy-mm-dd: How i write the validation rule for date as a format yyyy-mm-dd...validationrule for date as format yyyy-mm-dd in drools  Please give...("outofServiceStartDate", "stmpOutOfServiceStartDateInvalid", "Please use the format yyyy-mm-dd
Java convert string to date from format yyyy-mm-dd hh mm ss
Java convert string to date from format yyyy-mm-dd hh mm ss  Hi, I have date in the string yyyy-mm-dd hh mm ss format. Now I will want this string date into the date format. How to convert string to date from format yyyy-mm-dd
convert yyyy-mm-dd hh mm ss to date in sql
convert yyyy-mm-dd hh mm ss to date in sql  Hi, How to convert yyyy-mm-dd hh mm ss to date in sql? Thanks   Hi, You should use following code in SQL DATE_FORMAT(STR_TO_DATE(my_date, "%Y/%m/%d %H:%i:%s.%f"), "%Y-%m
yyyy-mm-dd validation in javascript
yyyy-mm-dd validation in javascript   My form return value like (2011-10-05)yyyy-mm-dd ... my End date greater than my start date.. How to do validation in javascript
Mysql Date Expression
a format  'YYYY-MM-DD' and 'HH.MM.SS'. Timestamp columns are displayed...;   mysql> select current_timestamp() as Date; Output... to return the current date and time as Date fieldname. mysql>
java format date
java format date  Hi, How can I format the date in the following pattern? yyyy-MM-dd   import java.util.*; import java.text.*; class...-MM-dd"); String formattedDate=sdf.format(date
How to convert current date to dd mm yyyy format in Java?
How to convert current date to dd mm yyyy format in Java?  Hi, How to convert current date to dd mm yyyy format in Java? In my program I have to display the current date in the dd-mm-yyyy format to user on the website. How
How to convert current date to mm dd yyyy format in Java?
How to convert current date to mm dd yyyy format in Java?  Hi, How to convert current date to mm dd yyyy format in Java? Share me the program... for converting current date into MM-dd-yyyy format. Here is full code: package
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java and trying to write a program to get the current date. How to get the current date in Java? Thanks   Hi, Check the tutorial: Java program to get current date
String to Date format
SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date...("yyyy-MM-dd"); String formattedDate=sdf.format(date... ).... How to Change This values Like to database date format Eg(2011-01-20) using
Mysql Date Type
' records in 'yyyy-mm-dd' format. select emp_dob from employee: The select query return the emp_dob  records in "yyyy-mm-dd" format. The Date Type...; Mysql Date Type is used to show the date in "yyyy-mm-dd" format.The
select date in desired format
select date in desired format  how to select date from the database in DD/MM/YYYY format, because if i am trying select data from the database i am getting value in yyyy/mm/dd and time format like below "2012-05-07 00:00:00.0
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
Get current Date and Time
dateformat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); Date date=new Date...Get current Date and Time In this section we will discuss about how to get current date and time in java. Java provide two classes, Date and calendar which
How to convert date to UTC format in Java?
How to convert date to UTC format in Java?  Hi, What is UTC Date format and How to convert date to UTC format in Java? I need simple to learn... java.util.GregorianCalendar; import java.util.TimeZone; /* How to convert date to UTC format
JDBC : Current Date
() functions  return the current date in format 'YYYY-MM-DD'. CURRENT... as a value in 'YYYY-MM-DD HH:MM:SS' SYSDATE()  : It returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' . Example
JDBC: Get current Date and Time Example
in the format 'YYYY-MM-DD' You can get current date by writing ...JDBC: Get current Date and Time Example In this section, you will learn how... you can call CURTIME(). It returns current time in the format of 'HH:MM:SS
Insert current date into MYSQL database
the date in MySQL is by using DATE and the proper format of DATE is: YYYY-MM-DD...Insert current date into MYSQL database In this tutorial, you will learn how to insert current date into database. In most of the applications
date format to be updated with current date time
date format to be updated with current date time  package LvFrm...; JButton b1,b2; //for date month year entry String strD[]={"Day","1...); /*for date entry & adding date into panel 2 also addind panel
Mysql Date Select
you easy to understand how to get the current date from your database. The SELECT DATE ('YYYY-MM-DD') is used to return the current selected date. SELECT DATE... Mysql Date Select      
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object...-yyyy HH:mm:ss"); String datetext4=sdf4.format(date
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object...-yyyy HH:mm:ss"); String datetext4=sdf4.format(date
How to display current date in textbox - Date Calendar
How to display current date in textbox  Hi guys, I'm really need your...;% } This is my problem: I want to display current date in textbox... Date(); var month = currentTime.getMonth() + 1; var day
Java SimpleDateFormat Example
is being given which will demonstrate you about about how to format a date using..."; SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss... dt1 = new SimpleDateFormat("yyyy-MM-dd"); System.out.println("New
How to get of lastmodified file list between two times in java?
) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd... SimpleDateFormat("yyyy-MM-dd hh:mm:ss a"); } public boolean accept(File dir, String name... = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a"); FileFilterDateIntervalUtils

Ads