Results 1 to 5 of 5

Thread: ZmMsg date and time

  1. #1
    Ericx is offline Loyal Member
    Join Date
    Jul 2006
    Location
    Virginia Beach, VA
    Posts
    97
    Rep Power
    9

    Default 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!
    Code:
    var formatter = AjxDateFormat.getDateTimeInstance(AjxDateFormat.FULL);
    var xdate =  formatter.format(new Date(obj.date)) ;
    Last edited by Ericx; 02-11-2007 at 10:40 AM.
    EricX

  2. #2
    Ericx is offline Loyal Member
    Join Date
    Jul 2006
    Location
    Virginia Beach, VA
    Posts
    97
    Rep Power
    9

    Default 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.)

    /opt/zimbra/tomcat/webapps/zimbra/js/AjaxNewWindow_all.js


    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.
    Code:
    //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)) ;
    Now I can pass Xdate to my custom form and it's formatted the way I like it.

    ----
    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.
    Last edited by Ericx; 02-11-2007 at 10:39 AM.
    EricX

  3. #3
    JoshuaPrismon is offline Zimlet Guru & Moderator
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    Default

    Quote Originally Posted by Ericx View Post
    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.)

    /opt/zimbra/tomcat/webapps/zimbra/js/AjaxNewWindow_all.js


    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.
    Code:
    //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)) ;
    Now I can pass Xdate to my custom form and it's formatted the way I like it.

    ----
    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.

    This is great info, can you put it up on the wiki?

  4. #4
    Ericx is offline Loyal Member
    Join Date
    Jul 2006
    Location
    Virginia Beach, VA
    Posts
    97
    Rep Power
    9

    Default Update

    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.
    Code:
    	
    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;
    I'll try to post it on the wiki soon.
    EricX

  5. #5
    JoshuaPrismon is offline Zimlet Guru & Moderator
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    Default

    Quote Originally Posted by Ericx View Post
    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.
    Code:
    	
    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;
    I'll try to post it on the wiki soon.
    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).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Date AND Time in received column
    By skydve1 in forum Users
    Replies: 4
    Last Post: 09-21-2009, 12:28 PM
  2. How to display time and date in "Received" column
    By celeron in forum Administrators
    Replies: 3
    Last Post: 01-28-2009, 02:26 AM
  3. Time and Date Issue
    By menonumesh in forum Administrators
    Replies: 3
    Last Post: 04-18-2007, 06:06 AM
  4. Replies: 29
    Last Post: 02-18-2007, 07:45 PM
  5. Replies: 4
    Last Post: 12-19-2006, 06:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •