Results 1 to 9 of 9
  1. #1
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Default How to create date in the format like (Fri Oct 31 08:46:27 PM PKT 2008)

    Hi to all :),
    Hope you all will be fine.I want to ask if i want to create date in the format like Fri Oct 31 08:46:27 PM PKT 2008 then how can i do it.
    Also how can i create timestamp with the newly creating date.

    Thank you.

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    If you made a file then it got this method:
    Java Code:
    setLastModified(long time)
    set the time to the new "last edited" time
    It should work..

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    See the API docs SimpleDateFormat.

  4. #4
    pansylea is offline Member
    Join Date
    Feb 2009
    Posts
    20
    Rep Power
    0

    Default

    try

    Java Code:
    System.out.println(" 1. " + now.toString());
    OR

    Java Code:
    System.out.println("10. " + DateFormat.getDateTimeInstance(
                DateFormat.LONG, DateFormat.LONG).format(now));

  5. #5
    pansylea is offline Member
    Join Date
    Feb 2009
    Posts
    20
    Rep Power
    0

    Default

    for Timestamp

    Java Code:
    public class MainClass {
    
      public static void main(String[] args) {
    
        java.util.Date today = new java.util.Date();
        System.out.println(new java.sql.Timestamp(today.getTime()));
    
      }
    
    }

  6. #6
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Question

    Hi,
    Thanks for your replies, these all help me a lot :). I created date like this

    Java Code:
            String pattern = "EEE MMM dd hh:mm:ss a z yyyy";
    
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            
            System.out.println(format.format(new Date()));
    And the output is

    Wed Dec 16 04:31:03 PM GMT+05:00 2009

    But i want that instead of GMT+05:00 it shows PKT means Pakistan time. All is fine only GMT+05:00 should be replace with PKT. How can i do it.

    Thank you.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    reread reply #3

  8. #8
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Default

    Hi,
    Hope you all will be fine.I did, i also tried
    Java Code:
    System.out.println("10. " + DateFormat.getDateTimeInstance(
                DateFormat.LONG, DateFormat.LONG).format(now));
    but the GMT is still there and when i check the timezone it also gave me GMT instead of PKT any ways leave it.

    Now i also asked about the timestamps and Pansylea replied that try

    Java Code:
        Date today = new Date();
        System.out.println(new java.sql.Timestamp(today.getTime()));
    But i got timestamp in the form

    2009-12-17 15:39:06.777
    and i want it in the form like below
    1225467987
    i.e., 10 character long.How can i do it.

    Thank you.

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And did you notice the "setTimezone" method of SimpleDateFormat?

    Edit: As, obviously, the time will be printed with whatever timezone applies to SimpleDateFormat (which is not, at all, dependant on that which was in the parse string, and which defaults to the system timezone).

Similar Threads

  1. julian date to full date format
    By judy318 in forum New To Java
    Replies: 7
    Last Post: 11-02-2009, 12:17 PM
  2. Date Format
    By learnspring in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 05:16 PM
  3. how to convert date format
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-16-2008, 06:10 PM
  4. Simple Date Format
    By arimakidd in forum Java Applets
    Replies: 1
    Last Post: 09-29-2008, 04:46 AM
  5. problems with Date format
    By tommy in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:38 PM

Posting Permissions

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