Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: SimpleDateFormat

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default SimpleDateFormat

    I have the following code:
    package com.wowza.wms.example.module; 
    import org.apache.log4j.Level; 
    import com.wowza.wms.logging.*; 
    import com.wowza.wms.stream.IMediaStream; 
    public class NewLogFields implements ILogNotify 
    { 
    public void onLog(Level level, String comment, IMediaStream stream, 
    String category, String event, int status, String context) { 
     
    long systime = System.currentTimeMillis(); 
    WMSLoggerFactory.putGlobalLogValue("systime-long", new Long(systime)); 
    } 
    }


    that provides the variable 'systime-long' with the date output of
    1278538830508
    but instead I would like the output to be like
    [07/Jul/2010:16:45:28 -0400]
    I have found that 'SimpleDateFormat' might work for me with the date format of
    [d/MMM/yyyy:HH:mm:ss Z]
    but I unfortunately am not Java savvy.

    Can anyone help with with this?

    Thanks in advance.


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: SimpleDateFormat

    You can just use Java's date/calender API.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: SimpleDateFormat

    The following outlines how you can use the SimpleDateFormat class:

    SimpleDateFormat sdf = new SimpleDateFormat("mm.dd.yy");
    System.out.println(sdf.format(new java.util.Date()));

    Look at the API for SimpleDateFormat (Java 2 Platform SE 5.0)
    for more info on how you can use the constructor to format the output.

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: SimpleDateFormat

    Quote Originally Posted by Brt93yoda View Post
    You can just use Java's date/calender API.
    Not sure how. Can you advise on how to do that?

    Quote Originally Posted by copeg View Post
    The following outlines how you can use the SimpleDateFormat class:

    SimpleDateFormat sdf = new SimpleDateFormat("mm.dd.yy");
    System.out.println(sdf.format(new java.util.Date()));

    Look at the API for SimpleDateFormat (Java 2 Platform SE 5.0)
    for more info on how you can use the constructor to format the output.
    I think you are correct, but I am not sure how to incorporate that into my code. I do suspect the format for the output is: [d/MMM/yyyy:HH:mm:ss Z]

    Any advice how how to incorporate it into my code?

    Thanks!

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: SimpleDateFormat

    Quote Originally Posted by smrtalex View Post
    I think you are correct, but I am not sure how to incorporate that into my code. I do suspect the format for the output is: [d/MMM/yyyy:HH:mm:ss Z]

    Any advice how how to incorporate it into my code?

    Thanks!
    You could try to pass the format function in replacement of the Long however I'm guessing this will not work given the parameter value seems to specify a long via 'systime-long'...
    WMSLoggerFactory.putGlobalLogValue("systime-long", sdf.format(new Date()));
    I'm unfamiliar with the WMSLoggerFactory class, but if this does not work for you may try to investigate whether there is another key you can use instead of systime-long which specifies a String or a date.

  6. The Following User Says Thank You to copeg For This Useful Post:

    smrtalex (July 7th, 2010)

  7. #6
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: SimpleDateFormat

    Thank you!!!!! That worked!!!!