Time Break Up

		// this piece of code breaks up the date and time part of a Date
		java.util.Date today = java.util.Date();
		SimpleDateFormat timeFormat = new SimpleDateFormat("kk:mm");
		String timeString = timeFormat.format(today);

		try {
			onlyTime = timeFormat.parse(timeString);
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		String dateString = dateFormat.format(today);

		try {
			onlyDate = dateFormat.parse(dateString);
		} catch (ParseException e1) {
			// TODO Auto-generated catch block


	// this snippet sets the time part of one date to another date
	public java.sql.Timestamp setDateAndTime(java.util.Date date,
			java.util.Date time) {

		Calendar calendar = Calendar.getInstance();
		Calendar calendar2 = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, calendar2.get(Calendar.HOUR_OF_DAY));
		calendar.set(Calendar.MINUTE, calendar2.get(Calendar.MINUTE));
		calendar.set(Calendar.SECOND, calendar2.get(Calendar.SECOND));
		java.util.Date dateWithTime = calendar.getTime();
		java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(

		return sqlTimestamp;

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: