ZmMsg date and time
Working on a Zimlet, needed to get email message time inside of a doDrop
There is got to be a better way but this worked. Took me 3 hours to hunt this down!
var formatter = AjxDateFormat.getDateTimeInstance(AjxDateFormat.FULL);
var xdate = formatter.format(new Date(obj.date)) ;
Custom Date Time!
I'm sure for the experienced java guys custom date and time is pretty easy. But for PHP users... this write up should save you a bunch of time.
Zimbra uses a custom date formatting class AjxDateFormat. It's similar to the well documented Java Simpledateformat class, but I can't get to that class very easy from within a zimlet. There are probably some other benefits from using the Zimbra custom AjxDateFormat class. If you want to see some of the options and usage for that class you con look at the file, as well as the source class. ( I have not posted where the source class is, short on time, but do a search through the source code and you can find it.)
In the above mentioned file you can search for AjxDateFormat to see many of the options. There are some already built options like
.short, .medium, .long, .full as well as some to get the month name and such. I'm using the date meta options to create the date exactly as I want it. This is more what I'm used to doing in PHP and should be familiar to php users.
My java object is obj.date. This outputs as a string or int, not really sure what it is, but not a date object. We have to stuff obj.date into a new date object so we can format it.
Now I can pass Xdate to my custom form and it's formatted the way I like it.
//obj.date is the time of our email message from doDrop.
var formatter =new AjxDateFormat("yyyy-mm-dd HH:mm:ss");// example output 2007-01-09 17:30:20
var Xdate = formatter.format(new Date(obj.date)) ;
If you want something that the user can read more easily. Create two inputs in your form
1. readonly using .long which should look something like Friday, Jan 9 1971 (this is from memory so don't quote me on it).
2. a hidden input field with the value = to the date you want to pass into your other database. Something like mike which looks like 2007-01-09 17:30:22.
Originally Posted by Ericx
This is great info, can you put it up on the wiki?
My previous code did not work so well. It looked like it worked but the month was giving me the minutes. This is how I got around it.
I'll try to post it on the wiki soon.
var formatter_date =new AjxDateFormat("yyyy-MM-dd");
var formater_time = new AjxDateFormat("HH:mm:SS");
var pretty_date = formatter_date.format(new Date(obj.date));
var pretty_time = formater_time.format(new Date(obj.date));
this.email_dtime = pretty_date + " " + pretty_time;
Makes sense, that's pretty close to the pattern that you see in Java. The only thing negative I will ever say about Zimbra is that the DWT code (quite deliberately I believe) very much is modeled directly on SWT/Swing/Java patterns. I think that's part of the reason that DWT "feels" much heavier then YUI, Prototype/etc (all things that I have been playing with recently).
Originally Posted by Ericx