Solved

getDayOfMonth() issue

Posted on 2007-12-06
2
266 Views
Last Modified: 2013-11-23
Experts,

I need a date in the format yyyyMMdd using the following:
String valDate_yyyyMMdd = ""+valuationDate.getYear()+""+valuationDate.getMonth()+""+valuationDate.getDayOfMonth()
but it returns 2007127 instead of 20071207

Please help!

Thanks,
Margin_Walker
0
Comment
Question by:Margin_Walker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
gatorvip earned 30 total points
ID: 20420383
Why not use SimpleDateFormat?

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String result = sdf.format(  your_date );
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 20420423
Here is the sample code

import java.text.*;
import java.util.*;

public class Test
{
  public static void main(String args[]) throws Exception
  {
    DateFormat df = new SimpleDateFormat("yyyyMMdd");;
    Date date1 = new Date(2007-1900, 12-1, 7);
    System.out.println(df.format(date1));
  }
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question