View Single Post
  #2 (permalink)  
Old 08-06-2007, 12:19 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.text.*; import java.util.*; // Prepare a formatter. See SDF api for options. DateFormat df = new SimpleDateFormat("HHmm ddMMMyyyy"); // Get a Calendar instance. Calendar calendar = Calendar.getInstance(); System.out.println("now = " + df.format(calendar.getTime())); // Get the time. Assume time is in 24 hour format. String timeStr = "0612"; // 6:12 am int hours = Integer.parseInt(timeStr.substring(0,2)); int minutes = Integer.parseInt(timeStr.substring(2)); // Set this time into todays calendar date. calendar.set(Calendar.HOUR_OF_DAY, hours); calendar.set(Calendar.MINUTE, minutes); // Check the result. System.out.println("timeStamp = " + df.format(calendar.getTime()));
Reply With Quote