Solved

Simlpe Time question

Posted on 2004-09-28
7
225 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

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

Suggested Solutions

Title # Comments Views Activity
hibernate example using maven 12 111
Facing this issue for maven proxy setting 2 45
JAVA API design with micro service cloud in mind 1 114
Setup GlassFish 4 56
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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

751 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