Combining TimeItem and DateItem values - java

I have to combine the time value for TimeItem and date value from DateItem in smartgwt.In output I want the date object for java.util.Date.I tried to combine these two.I couldnot do that.
Sample code is :
DateItem date=new DateItem();
TimeItem time=new TimeItem();
DynamicForm form=new DynamicForm();
form.setFields(date,time);
// java.util.Date selectedDate= ? Here I need the output
Can anyone help on this? thanks

I haven't tried this, but this is my educated guess:
You can set the dateItem.setInputFormat(...) and dateItem.setDisplayFormat(...) using a date format that also includes time.

Related

Lotus Notes : Insert date value in Lotus Notes form using java agent

I am trying to upload the data from a delimited text file to the lotus notes form using java agent. The issue arises when I try to insert the date value to the notes document. After insert when i use ComputeWithForm, then it returns false. I am using simpledateformat to format the date in MM/dd/yyyy format, but it is still not working. Below is the excerpt from my code.
String delim, key, thekey, myDate;
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy);
myDate = dateFormat.format(date);
newdoc.replaceItemValue("UploadDBDate", myDate);
Any help will be great.
Thanks,
Himanshu
myDate is a String object. The replaceItemValue method does not know that you have put a date into that String, therefore it treats it as ordinary text. If uploadDBDate is a DateTime field, that causes a type mismatch during the computeWithForm operation.
The Lotus classes for Java include a DateTime class. The Session class has a createDateTime method that you pass a "mm/dd/yyyy" string and return a DateTime object. Then you can pass that DateTime object into replaceItemValue instead of passing in myDate.
I would recommend you to do those things:
1) disable computewithform and simply save document and then verify field UploadDBDate, does it have correct value? does it have corrrect type?
2) if everything is fine with UploadDBDate then there is a problem on a form, so try to investigate what calculation you do on the form, because problem is there.

request.getParameter String value pass as date to java

In my JSP page I have a field which is date and when I getting as request.getParameter("dateVal"); gives me
15-Dec-2012 12:21.
I would like to pass this value to my database procedure and insert/update into table.
How can I pass the value as setDate using prepareCall to database?
Thanks
First step would be using SimpleDateFormat to parse it to a fullworthy java.util.Date instance in the controller:
Date date = new SimpleDateFormat("dd-MMM-yyyy HH:mm.", Locale.ENGLISH).parse(dateVal);
Then you can just create a java.sql.Date around its time in the database layer:
statement.setDate(1, new java.sql.Date(date.getTime()));
Unrelated to the concrete problem, please note that java.sql.Date doesn't remember the time part. If you have actually a DATETIME or TIMESTAMP field in the DB and not a DATE field, then rather use setTimestamp() with a java.sql.Timestamp instead. This way the time part will also be stored.
#BalusC 's answer is perfect. But as an alternative solution you can use the function provided by database to convert String to Date while querying. For example(in case you use Oracle),
to_date(date_in_String, format)
Try this :
new SimpleDateFormat("dd-MM-yyyy HH:mm").parse(mydate);

Google Calendars API - setTimeMax causing error

I'm trying to retrieve a list of events from a google calendar, using the Java api (jar version v3-rev9-1.7.0-beta)
This code works fine
Events e = service.events().list("primary").
setMaxResults(3).
execute();
where service is a Calendar object.
However, if I add a setTimeMin or setTimeMax parameter, like this
Date now = new java.util.Date();
Events e = service.events().list("primary").
setTimeMin(new DateTime(now)).
setMaxResults(3).
execute();
it returns a failure message, "Bad Request".
(note that as of this version, the setTime functions take a google DateTime object. I've also tried with the previous version of the jar, which takes a string, but received the same message).
So I was just wondering if anyone has successfully used these functions - perhaps they're not supposed to be called in this manner? Is there a way to get more detail back on the error?
Thanks :)
DateTime startTime = new DateTime(new Date(), TimeZone.getDefault());
Sorts the problem
I also encountered this. It seems the format of the DateTime.toString() or DateTime.toStringRfc3339() methods are incorrect as input to setTimeMin().
The DateTime.toString() format is:
2012-07-04T21:02:16.590
yyyy-MM-dd'T'HH:mm:ss.SSS (SimpleDateFormat notation)
The format which it expects seems to be close to xsd:datetime format (whatever that is):
2012-07-04T21:02:16Z (zulu, gmt)
2012-07-04T21:02:16-07:00 (mst, -7h)
2012-07-04T21:02:16-0700 (it also works without the colon in the timezone)
yyyy-MM-dd'T'HH:mm:ssZ (SimpleDateFormat)
Formatting can be done with a SimpleDateFormat:
SimpleDateFormat FMT_TIME=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String fromTimeStr=FMT_TIME.format(new Date());
Events evts = client.events().list(cal.getUid()).setTimeMin(fromTimeStr)
.execute();
Now, since I'm using the older API, I'm not sure how this would be done if the only method is setTimeMin(DateTime), but this should get you closer.
The Google documentation or source should mention this somewhere.

JSON parse date and time?

Im having a little issue with parsing json date.
Here is what I would like to parse:
{"driver": "247","firstName": "XXXXX","lastName": "XXXXX","lastLatitudeUpdate": "5/21/2012 4:49:17 PM","suspended": "false","checkedin": "0"}
I am having trouble parsing "lastLatitudeUpdate" is it because there are spaces in between? Thanks in advance for the help.
Assuming you are on Android and therefore working with java (yes you don't mention that, only the tag in your question suggests it...)
Like mentioned here (and in various other places) you can parse a date in java using the SimpleDateFormat class:
SimpleDateFormat parserSDF=new SimpleDateFormat("M/d/yyyy h:m:s a");
Date d = parserSDF.parse(dateField,0);
Of course you have to first parse you json input with some library (e.g. standard library from json.org or Google gson) and then parse the string you'll get there for the field into a date.
Short answer: No, there is no way for the JSON engine to recognize a string as a Date object.
Long answer:
There is no 'date' type in JSON. However, this JSON is fine, the catch is that lastLatitudeUpdate will be parsed as a string. In order to convert this to a date you should try something like
var my_object= JSON.parse({"driver": "247","firstName": "XXXXX","lastName": "XXXXX","lastLatitudeUpdate": "5/21/2012 4:49:17 PM","suspended": "false","checkedin": "0"});
my_object.lastLatitudeUpdate= Date.parse(my_object.lastLatitudeUpdate)
This function will give a timestamp. However, you have to make sure the string is correctly recognized, you may have to do some extra work.
Some links for hints
http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
http://www.java-samples.com/showtutorial.php?tutorialid=406
How are you parsing the date? In Chrome this seems to work fine:
new Date("5/21/2012 4:49:17 PM");
Mon May 21 2012 16:49:17 GMT-0400 (US Eastern Daylight Time)

faced with date parsing problem in jexcel api

I have created a file named tablenew.xls which has date with following code:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date)formatter.parse(st[length]);
datecell=new DateTime(tokenNumber,lineNumber,date);
sheet.addCell(datecell);
I am getting the output in my file as "04-03-11" which is "dd-MM-yy".
However when this same date is written to another file named tabletemp.xls with the same code , i get the output as something like -689881.5. My dilemma is that the my program however, seems to understand this negative value as a date. Should i modify my code? if so, then what should i do?
thanks in advance
Problem is solved. Thanks anyways. As always, the date "04-03-11" was displayed as
"dd-MM-yy" , was however treated by excel as "MM/dd/yy" .
Jexcel should look into this problem. Their date parsing is a big pain.

Categories