How to get Current date from computer in java

Discussion in 'Java' started by sandesh17, Jun 5, 2013.

  1. sandesh17

    sandesh17 New Member

    Joined:
    Jun 5, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    How to get current in java? Not from system's date because anyone can change it....
    I want current to validate my application expiry...please help me...thanx in advance...
     
  2. Exquisite

    Exquisite New Member

    Joined:
    Aug 5, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    xxx
    Are you on javascript or java
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Why do you think this is in JS?
     
    Exquisite likes this.
  4. sparticus

    sparticus Banned

    Joined:
    Sep 9, 2013
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programming
    Location:
    Canada
    Unless you query an external time server, you will never know whether the given system time is accurate. This would require an internet connection however. I don't honestly think someone will change their system clock, which in turn will screw up a lot of other applications, to simply circumvent your application expiry logic.
     
  5. ArnavKumar

    ArnavKumar New Member

    Joined:
    Oct 30, 2013
    Messages:
    4
    Likes Received:
    1
    Trophy Points:
    0
    You can use your database for this purpose. In this case your database will say your program what date is to pick and if you want to make some change it will be done in the database neither in the system nor in the program.
     
  6. alia123

    alia123 New Member

    Joined:
    Jan 8, 2016
    Messages:
    65
    Likes Received:
    5
    Trophy Points:
    0
    Hey, here’s the code I’m sharing to get in the date and time just check this :

    Code:
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    
    public class GetCurrentDateTime {
      public static void main(String[] args) {
    
           DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
           //get current date time with Date()
           Date date = new Date();
           System.out.println(dateFormat.format(date));
          
      }
    }
     
  7. Jeff Ronald

    Jeff Ronald Member

    Joined:
    Dec 9, 2016
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    6
    Gender:
    Male
    Home Page:
    http://ezmoov.com
    Thank you for the information.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice