Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Simlpe Time question

Posted on 2004-09-28
Medium Priority
227 Views
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
Question by:jaggybala1
[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
• 6

LVL 37

Expert Comment

ID: 12168715
Use SimpleDateFormat.parse()
0

Author Comment

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

LVL 37

Expert Comment

ID: 12168728
SimpleDateFormat sdf = new SimpleDateFormat("EE, dd.MM.yyyyhhmm");
String tmp = date + hours + minutes;
Date myDate = sdf.parse(tmp);
0

LVL 37

Expert Comment

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

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

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

ID: 12169402
Thanks for accepting
0

## Featured Post

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectioâ€¦
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 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â€¦
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
###### Suggested Courses
Course of the Month8 days, 6 hours left to enroll

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

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