Home Answers Viewqa Java-Beginners how to format date from yyyy-mm-dd to dd-mm-yyyy

 
 


Wangdi
how to format date from yyyy-mm-dd to dd-mm-yyyy
1 Answer(s)      3 months and 16 days ago
Posted in : Java Beginners

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<html>
<head>
<script type="text/javascript">
    var bas_cal,dp_cal,ms_cal;      
window.onload = function () {
    dp_cal  = new Epoch('epoch_popup','popup',document.getElementById('dob1'));
    dp_cal  = new Epoch('epoch_popup','popup',document.getElementById('dob2'));

};
</script>
<script type="text/javascript">
function findDiff(){
var dob1= document.getElementById("dob1").value;
var dob2= document.getElementById("dob2").value;
var date1 = new Date(dob1);
var date2=new Date(dob2);

var ONE_DAY = 1000 * 60 * 60 * 24
var d1 = date1.getTime()
var d2 = date2.getTime()
var diff = Math.abs(d1 - d2)
document.getElementById("days").value=Math.round(diff/ONE_DAY);
}
</script>

</head>
<body>
<?php include "includes/header.php";?>
<pre>
Enter Date1(yyyy-mm-dd): <input type="text" name="dob1" id="dob1" />
Enter Date2(yyyy-mm-dd): <input type="text" name="dob2" id="dob2" onblur="findDiff()" />
Number of days: <input type="text" name="days" id="days" />
<!-- <input type="submit" value="calculate" onclick="findDiff();"> -->
</pre>
</body>
</html>
</body>
</html>

In the above code, inorder 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 appreciated for your help and support.

View Answers

February 9, 2013 at 7:13 PM


hi friend,

you can use the SimpleDateFormat() class for formatting the date. This class takes the argument as a String.

For detail tutorial please go through the following link may this will be helpful for you.

Date Format Example









Related Pages:
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
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
php date format yyyy-mm-dd
php date format yyyy-mm-dd  date format yyyy-mm-dd validation
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 in microsoft sql server?  how to convert the entire column field which is in encryted like 1263332444 of table to dd/mm/yyyy format in microsoft sql server? i
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
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
Mysql Date Expression
; 'YYYY-MM-DD' and 'HH.MM.SS'. Timestamp columns are displayed in the same format... Mysql Date Expression       The Tutorial illustrate an example from 'Mysql Date Expression
Validating date in javascript - Java Interview Questions
; In what format you are going to enter the date in Text box (i.e : dd/mm/yyyy or mm/dd/yyyy or yyyy/mm/dd...Validating date in javascript   Hi Deepak, Can u give
Change Date Format - Development process
Change Date Format  Hi, While retrieving data frm database, date format displayed as yyyy/mm/dd but i want to display as dd/mm/yyyy. I have tried parse,format functions but not getting output. can u send me code
date format - Java Beginners
date format  How to convert yyyy-mm-dd to dd-mmm-yyyy  Hi friend, Code to convert yyyy-mm-dd to dd-mmm-yyyy : import java.util.Date...(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd
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
hi
hi  sql date format is yyyy/mm/dd and user enter dd/mm/yyyy in textfields so when insert textfield value in sqldatabase table so how can convert date format so insert date store in sql table
Retrieve date from MYSQL database
. The default format of date in MYSQL is YYYY-MM-DD. Example import java.sql....Retrieve date from MYSQL database In this tutorial, you will learn how...("dd/MM/yyyy"); System.out.println(sdf.format(dd)); } } catch (Exception e
date format - JSP-Servlet
"; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date dateStr...); System.out.println("yyyy-MM-dd date is ==>"+formattedDate); Date...); System.out.println("dd-MMM-yyyy date is ==>"+formattedDate); } } Thanks
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
Formatting a Date Using a Custom Format
) { Date date = new Date(); SimpleDateFormat f = new SimpleDateFormat("dd-MM-yyyy...Formatting a Date Using a Custom Format In this section, you will learn how to format a date using a custom format. Java has provide many classes that allow
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
Struts 2 Date Format Examples
in (yyyy-MM-dd) Format:</td> <td> <b><s:date name...; <tr> <td>Date in (dd-MMM-yyyy hh:mm AM/PM) Format:<...; <tr> <td>Date in (dd/MM/yyyy hh:mm) Format:</td>
Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql
How to Store Date - Java Beginners
JFrame{ InsertDate(){ JLabel l=new JLabel("Enter Date (dd/MM/yyyy...(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String todayDate=sdf.format(d...How to Store Date  How to Validate date in JTextField ,How I can
JavaScript calculate age from date of birth
{ alert("Invalid date format. Please Input in (dd/mm/yyyy) format... date format. If inputted date of birth is in form of dd/mm/yyyy... format (dd/mm/yyyy) if (pattern.test(dob)) { var y1
Date Formay - Date Calendar
)) System.out.print("Current date(" + new SimpleDateFormat("dd/MM/yyyy"). format...("dd/MM/yyyy").format(cal.getTime())); else if(cal.after(currentcal)) System.out.print("Current date(" + new SimpleDateFormat("dd/MM/yyyy"). format
struts2.2.1 date Format example
;Date Format(EEEE yyyy-MM-dd):</b><br/><br/> <s:date...; <b>Date Format (EEEE MM/dd/yyyy hh:mm AM/PM):</b><br/><.../yyyy 'at' hh:mm a" /> <hr> <b>Date Format (EEEE dd-MMM
Java - Java Interview Questions
Scanner(System.in); SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy... = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(sdf.format(date...Java  1)Write a program in java to take input date from the user
java yesterday - Date Calendar
java yesterday  And how to make date format DD/MM/YYYY,thank's ... static void main(String args[]){ Date todaysDate = new java.util.Date(); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); String
Date format - Date Calendar
Date format  Hi All, I am getting a date from database as a format...); SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy... field.Every time i need to check the format of the date field and make sure the correct
how to set image - EJB
(); /** Converts the date(dd/mon/yyyy) format to DD/MM/YYYY format*/ String sfromdate...=sampleJasperReportForm.getTo_date(); /**Converts the date(DD/MM/YYYY) format to YYYY-MM-DD format...(); jrDesignQuery.setText("select * from emp_header where (DATE_FORMAT(creation_date
Format date/time using <fmt:formatDate> tag of jstl
to format. For example: dd-mm-yyyy timeZone... pattern="yyyy-MM-dd hh:mm:ss" value="${date}" /></td>... in this section we will explain how to format date/time as per user requirment by using
date_parse_from_format
  date_parse_from_format date_parse_from_format function returns... about given date. Description on PHP Date Parse Format array date_parse_from...:00"; print_r(date_parse_from_format("j.n.Y H:iP", $date
String to date with no format
date format can be (mm-dd-yyyy) if the 99th record also was 06-06-2006 the result should be date format can be (mm-dd-yyyy;dd-mm-yyyy) can sum1 please help me... into a date .. this is simple .. but i want to do it without knowing the date format
DATE
sdf = new SimpleDateFormat("dd-MM-yyyy"); System.out.println(sdf.format... of calcultion starts My question is how to find the date of Thursday This cycle...DATE  I have the following as my known parameter Effective Date
java - JSP-Servlet
java  how to calculate the days from two dates in format(DD/MM/YYYY
Java Date format - Java Server Faces Questions
(DD/MM/YYYY).   Hi friend, Code to calculate days between two dates in format(DD/MM/YYYY) import java.util.Date; import... format SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yyyy
date format in javascript
date format in javascript  display date format as dd/mm/yyyy and day... help me. thank u var date=/^\d{2}\/\d{2}\/\d{4}$/ if(document.userform.joindate.value.search(date)==-1) { alert("please enter date format as dd/mm/yyyy
Date related query - Date Calendar
date in one format System.out.println("Enter Start Date in Format DD/MM... in Format DD/MM/yyyy"); String strDate1 = br.readLine(); try... SimpleDateFormat sdfSource = new SimpleDateFormat("DD/MM/yyyy
standard format in C++
standard format in C++  Please help me with this one. thank you so much. **"Write a C++ program to read a date in US standard format (mm dd yyyy) and print it in Australia standard format (dd mm yyyy
java - JSP-Servlet
java  how to calculate the days from two dates in format(DD-MM-YYYY...(DD-MM-YYYY). import java.util.Date; import java.text.ParseException... SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MM-yyyy
ask how function jCalender - Date Calendar
{ if(jTextField4.getDate() != null) { String pattern = "yyyy-MM-dd...ask how function jCalender  d, Halo friend, i want to ask how to make this script can run and call JCalender. I want to know how to make private
continue java - Date Calendar
continue java  How to make a subtract date from jframe like jtexfield, data can input into jtextfied ? and how to get year, yesterday a have a question about how to substract dd mm yyyy can in this subtract have a year.thank
Mysql Date Select
; The Tutorial elaborate an example from 'Mysql Date Select'. This section makes 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
Change Date Format - Development process
Change Date Format   Hi, i hav used following line get date field from database . But my output is 2009/26/5. How to change the format
PHP date_create_from_format function
date_create_from_format  function The date_create_from_format... according to the specified format. Parameters format Format accepted by date... DateTime object formatted according to the specified format.  Description
Java Swing Date Difference
in the format dd-MM-yyyy using the SimpleDateFormat class. We have created...(); String d2=text2.getText(); Date date1 = new SimpleDateFormat("dd-MM-yyyy").parse(d1); Date date2 = new SimpleDateFormat("dd-MM-yyyy").parse
Mysql Date Format codes
in dd-mm-yy. mysql> select date_format(now(),'%e-%m-%y')as Date... Mysql Date Format codes       The Tutorial illustrate an example from 'Mysql date format
Date operation - JDBC
DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); String today = df.format(date... in a short format df = new SimpleDateFormat("EEE, dd/MM/yyyy"); today = df.format...("MM/dd/yyyy"); today = df.format(date); System.out.println("Today
Simple date formatter example
into the "yyyy-MM-dd HH:mm:ss" format. formatter = new SimpleDateFormat... we have formatted the date into  "yyyy-MM-dd" format. Here... formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String formattedDate
Date forms
object and how to parse a Date object into its equalent string format...;format = new SimpleDateFormat("yyyy-MM-dd");   ...; In this section we are demonstrating the retrieval of date from
date format - Date Calendar
date format  how to convert dd-mmm-yyyy date format to gregorian...="19-Sep-2008"; DateFormat format ; Date date ; format = new SimpleDateFormat("dd-MMM-yyyy"); date = (Date)format.parse(strDate); Calendar cal

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.