Results 1 to 2 of 2
  1. #1
    gita is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default how to validate a long value is in valid UTC time format

    a long value is passed in by user (datetimestamp value)

    need to validate if it is in a valid UTC format in java

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Every long value represents a valid date/time. But if you need to verify that it is within some range, then I suggest using a java.util.GregorianCalendar.

    Java Code:
    import java.util.*;
    ...
    
    Date date = new Date(longMsSinceUnixEpoch);
    
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    
    
    int year = cal.get(Calendar.YEAR);
    ...etc.
    A java.util.Date can be constructed from a long (representing ms since the unix epoch - midnight Jan 1 1970)

Similar Threads

  1. Long wait time before print job reaches printer
    By Astghik in forum AWT / Swing
    Replies: 0
    Last Post: 01-12-2010, 10:29 AM
  2. Convert String to Time format
    By plasma in forum New To Java
    Replies: 1
    Last Post: 12-16-2009, 08:58 AM
  3. Validate DATE format in applet
    By only2008 in forum Java Applets
    Replies: 4
    Last Post: 09-29-2009, 09:20 AM
  4. validate time input format
    By Alairmon in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 07:39 AM
  5. It takes very long time.....
    By iresha in forum Advanced Java
    Replies: 6
    Last Post: 05-11-2008, 02:31 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
  •