get current date in java in yyyy mm dd hh mm ss format

Ads
 

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

View Answers

July 21, 2017 at 4:48 AM

Hi,

Here is the complete example of getting current date into yyyy-mm-dd hh:mm:ss format.

package net.roseindia;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
 * Format current date into yyyy-mm-dd hh:mm:ss String
 * format
 */
public class FormatCurrentDate {
    public static void main(String[] args) {
        try {
            //Current date to yyyy-mm-dd hh:mm:ss
            Date currentDate = new Date();
            DateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
            String strCurrentDate = df.format(currentDate);
            System.out.println("Date is " + strCurrentDate);
        } catch (Exception e) {
            System.out.println("Exception :" + e);
        }

    }
}

Thanks

Ads









Related Tutorials/Questions & Answers:
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  
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... to convert string date in format yyyy-mm-dd hh mm ss to date object. We need
Advertisements
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
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
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...-dd"); formats the date into yyyy-MM-dd format. the MM is used for getting
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... it to yyyy-mm-dd String format. Here is Java example for converting String Date...How to convert date to string in Java in yyyy-mm-dd format  Hi, I
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
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
validationrule for date as format yyyy-mm-dd in drools  Please give... format yyyy-mm-dd: How i write the validation rule for date as a format yyyy-mm-dd...("outofServiceStartDate", "stmpOutOfServiceStartDateInvalid", "Please use the format yyyy-mm-dd
How to calculate sum of HH:MM:SS Format?
How to calculate sum of HH:MM:SS Format?  how to calculate sum of HH:MM:SS? for example: 10:25:36+26:50:56 calculate sum of these values
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
calculate milliseconds to hh mm ss
calculate milliseconds to hh mm ss  how to calculate milliseconds to hh mm ss ? Actually i wanted to calculate week days and hours from milliseconds..?   var seconds = (mil / 1000) | 0; mil -= seconds * 1000; var
how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server?
how to convert the entire column field of table to dd/mm/yyyy format... is in encryted like 1263332444 of table to dd/mm/yyyy format in microsoft sql server? i... to change entire date of column
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>
Get current Date and Time
dateformat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); Date date=new Date... DateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calender cal... SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); Calendar cal = Calendar.getInstance
Java program to get current date
Java program to get current date now  ...()); Above lines of code gets the current date and time in the yyyy/MMM/dd HH...;SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");   String 
how to get date format in string from date object containing real date in java
-yyyy HH:mm:ss"); String datetext4=sdf4.format(date...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
how to get date format in string from date object containing real date in java
-yyyy HH:mm:ss"); String datetext4=sdf4.format(date...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
Java Date Format Example
dd MMM yyyy HH mm ss Z"); String newDateString = dateFormat.format(date... MMM yyyy HH mm ss Z"); Date date = new Date(); String newDateString...("E dd MMM yy HH mm ss Z", Locale.FRENCH); A Simple Example is given below
Date validation in JSP
of validations are done: The date format should be : MM/DD/YYYY Month should be valid... in a specified manner then it will show error message date format should be MM/DD/YYYY... JavaScript for validating date in a specified format as "MM/DD/YYYY". We
JDBC : Current Date
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...() functions  return the current date in format 'YYYY-MM-DD'. CURRENT
JDBC: Get current Date and Time Example
in the format 'YYYY-MM-DD' You can get current date by writing ... you can call CURTIME(). It returns current time in the format of 'HH:MM:SS...JDBC: Get current Date and Time Example In this section, you will learn how
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
java program
","MM","dd","HH","k","mm","ss","SS","MM-dd-yyyy k:mm:ss.SS"}; for(int i=0...java program  write a java program to get current date and time in the following format: current year is:2007 current month is:12 current date is:23
java program 18
[]={"yyyy","MM","dd","HH","k","mm","ss","SS","MM-dd-yyyy k:mm:ss.SS"}; for(int...java program 18  write a java program to get current date and time in the following format: current year is:2007 current month is:12 current date
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java... in Java? Thanks   Hi, Check the tutorial: Java program to get current date. Thanks   Hi, To get the current date and time in Java you can use
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
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
Parsing date in Java
Parsing date in Java  How can i parse the date in Java in a simple format..?   SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy
Simple date formatter example
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String formattedDate... into the "yyyy-MM-dd HH:mm:ss" format. formatter = new SimpleDateFormat... we have formatted the date into  "yyyy-MM-dd" format. Here

Ads