typecast string to datetime

I wrote the below program to get date value based on the input parameter
The output for this code is currentDate which is a string object.
I am sending this output into a datetime field,
as i am returning string it cant fit into that field and showing me null

so is it possible to typecast this output CurrentDate into datetime format.

plz: Ignore few methods like IAdaptorParameter the whole point here is to convert string
to a format acceptable by datetime textbox.

Experiment :
CurrentDate = dateformat.format(rs2.getTime("systime"));

instead of above stmt I used

CurrentDate =rs2.getTime("systime");

so now it is date object and when i send this to datetime text field.

It showed output 8/4/2011 3:34:55 in date box nothing in seconds box
along with an error complaining not in data is not in the format
of mmm d,yyyy h:mm:ss a

so i used simple date format to do it...
import java.text.SimpleDateFormat;
import java.util.Date;

import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.tools.adaptor.AdaptorException;
import com.documentum.tools.adaptor.IAdaptorParameter;
import com.documentum.tools.adaptor.configuration.IAdaptorConfiguration;

public class DohCreateDateAdaptor implements IDohCustNameAdaptor{
	IDfCollection rs = null;
	String password = "passsword";
	String username = "username";
	String repositoryName = "docbase";
	IDfSession session = null;
	IDfSessionManager sMgr = null;
	IAdaptorParameter parameter = null;
	public Object execute(IAdaptorParameter[] parameters) throws AdaptorException {
		// TODO Auto-generated method stub
		Object CurrentDate = null;
		Object request_object_id = null;
		String pattern = "mmm d,yyyy h:mm:ss a";
		SimpleDateFormat dateformat = new SimpleDateFormat(pattern);
		if(parameters.length == 1)
			IAdaptorParameter parameter = parameters[0];
			request_object_id = parameter.getObject();
		try {
			new DfClient();
			IDfClient client = DfClient.getLocalClient();
			sMgr = client.newSessionManager();
			IDfLoginInfo logininfo = new DfLoginInfo();
			sMgr.setIdentity(repositoryName, logininfo);
			session = sMgr.getSession(repositoryName);	
			IDfQuery query = new DfQuery();
			IDfQuery query1 = new DfQuery();
			//IDfQuery query2 = new DfQuery();	
				query.setDQL("SELECT DATE(now) as systime from dm_server_config"); 
				rs2 = query.execute(session, DfQuery.DF_READ_QUERY);
				while(rs2.next()) {
					CurrentDate = dateformat.format(rs2.getTime("systime"));
				query1.setDQL("select r_creation_date from dm_document where r_object_id = "+"'"+request_object_id+"'");
				rs1 = query1.execute(session, DfQuery.DF_READ_QUERY); 
				while(rs1.next()) {
					CurrentDate =  dateformat.format(rs1.getTime("r_creation_date"));
		catch(DfException e){
		catch(Exception e) {
		finally {
		return CurrentDate;
	public void destroy() throws AdaptorException {
		// TODO Auto-generated method stub
	public void init(IAdaptorConfiguration arg0) throws AdaptorException {
		// TODO Auto-generated method stub

Open in new window

Who is Participating?
Yes, now I checked,actually it was correct

String s = "8/4/2011 3:55:00 am";
SimpleDateFormat f = new SimpleDtaerForma("MM/dd/yyyy hh:mm:ss a);
Date d;
String sDate = f.format(d);

This has  examples of patterns:
Your pattern does not match the actual format of your date srring.
It should be:

SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
(Check upper and lower case for mm, MM
In SimpleDataFormat API - I don't have access right now, but the general format is as I wrote)
If your time is I AM/PM then it should be
"MM/dd/yyyy hh:mm:ss a"
But there should not be any comma, as you specified
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Sathish David Kumar NArchitectCommented:
>>CurrentDate = dateformat.format(rs2.getTime("systime"));

should be

CurrentDate = dateformat.format(rs2.getTimestamp("systime"));

Open in new window

>             String pattern = "mmm d,yyyy h:mm:ss a";

As for_yan points out above, your format is wrong
for a start your using mmm for the month (M is month)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.