Solved

getDayOfMonth() issue

Posted on 2007-12-06
2
264 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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

808 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