Solved

Simlpe Time question

Posted on 2004-09-28
7
226 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
[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
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 50 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

617 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