Solved

getDayOfMonth() issue

Posted on 2007-12-06
2
262 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 81
Eclipse Neon and jdk 1.8.0 11 138
Image decoding from Camera 3 72
HTTPSessionBindingListernter not configured in deployment descriptor 2 39
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now