cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lothar Krenzien <lkrenz...@web.de>
Subject Re: how does cayenne handle java.util.date values ?
Date Tue, 05 Dec 2006 17:19:12 GMT

> -----Ursprüngliche Nachricht-----
> Von: cayenne-user@incubator.apache.org
> Gesendet: 05.12.06 14:33:50
> An: cayenne-user@incubator.apache.org
> Betreff: Re: how does cayenne handle java.util.date values ?


> On Dec 5, 2006, at 14:26 , Lothar Krenzien wrote:
> 
> > I've provided a simple demo class to show what I mean. I used Java  
> > 5, cayenne 2.1 and jtds with MS SQL Server 2000.
> 
> Looks like the attachment are striped by the mail-list software.  
> Could you copy/paste the code into the mail instead of attaching the  
> java file?
> 
>   - Tore.
> 

Ok here's the sample :

------------------------------------------------------------------

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;


public class CayenneDateTest {


	public static void main(String[] args) {
		try {
			System.out.println("litte java date parsing + formating sample");
	        doTest();
        }
        catch (Exception e) {
	        e.printStackTrace();
        }
	}

	private static void doTest() throws Exception {
		// the string value from the xml file
		String dateValue = "28.10.2006 22:14:28";
		TimeZone timeZone = TimeZone.getTimeZone("Asia/Seoul");
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
		dateFormat.setTimeZone(timeZone);
		Date parsedDate = dateFormat.parse(dateValue);
		System.out.println("parsedDate:" + parsedDate); // this will be stored by cayenne

		dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss zzzz");
		dateFormat.setTimeZone(timeZone);
		String formattedDate = dateFormat.format(parsedDate);
		System.out.println("formattedDate:" + formattedDate);

		dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		dateFormat.setTimeZone(timeZone);
		formattedDate = dateFormat.format(parsedDate);
		System.out.println("formattedDate:" + formattedDate); // this is what I like to be stored
by cayenne
	}

	private static void doImport() {
		// this is a pseudo example how the real application does the db import

		/*
		String dataDate = "28.10.2006 22:14:28" ;
		TimeZone timeZone = TimeZone.getTimeZone("Asia/Seoul");
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
		dateFormat.setTimeZone(timeZone);
		Date parsedDate = dateFormat.parse(dataDate);
		TblImportEffBlockData importData = (TblImportEffBlockData)context.createAndRegisterNewObject(TblImportEffBlockData.class);
		importData.setDataDate(parsedDate);
		context.commitChanges();*/

		/*
		-- cayenne log output
		INSERT INTO dbo.tblImportEffBlockData
		(dataDate)

		bind: '2006-10-28 15:14:28.0'
		*/

		/*
		-- db table definition

		CREATE TABLE [dbo].[tblImportEffBlockData] (
			[importEffBlockDataId] [int] IDENTITY (1, 1) NOT NULL ,
			[dataDate] [datetime] NOT NULL
		) ON [PRIMARY]
		GO
		*/
	}
}

------------------------------------------------------------------
______________________________________________________________________________
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!


Mime
View raw message