Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simlpe Time question

Posted on 2004-09-28
7
Medium Priority
?
228 Views
Last Modified: 2010-03-31
I got 3 strings..

one is "date", second is "hours" and the third is "minutes". so for example,

String date = "Tu, 28.09.2004";
String hours = "09";
String minutes = "30";

now i want to convert this into a single DATE format. Like:

Date myDate = Tu, 28.09.2004 09:30;

thanks
0
Comment
Question by:jaggybala1
  • 6
7 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12168715
Use SimpleDateFormat.parse()
0
 

Author Comment

by:jaggybala1
ID: 12168722
could you tell me more, please? how should i use it?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12168728
SimpleDateFormat sdf = new SimpleDateFormat("EE, dd.MM.yyyyhhmm");
String tmp = date + hours + minutes;
Date myDate = sdf.parse(tmp);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 12168740
You probably need to catch a ParseException:

SimpleDateFormat sdf = new SimpleDateFormat("EE, dd.MM.yyyyhhmm");
String tmp = date + hours + minutes;
Date myDate = null;
try {
    myDate = sdf.parse(tmp);
} catch (ParseException ex) {
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12168763
Small correction if the hours are expressed in 0-23 format then replace

      SimpleDateFormat sdf = new SimpleDateFormat("EE, dd.MM.yyyyhhmm");
by
      SimpleDateFormat sdf = new SimpleDateFormat("EE, dd.MM.yyyyHHmm");  // HH instead of hh
0
 
LVL 37

Accepted Solution

by:
zzynx earned 200 total points
ID: 12168775
So, to conclude:

SimpleDateFormat sdf = new SimpleDateFormat("EE, dd.MM.yyyyHHmm");
String tmp = date + hours + minutes;
Date myDate = null;
try {
    myDate = sdf.parse(tmp);
} catch (ParseException ex) {
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12169402
Thanks for accepting
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

885 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