Solved

Simlpe Time question

Posted on 2004-09-28
7
222 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

770 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