Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get date of past days in java?

    • 0
    • 4
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 391
    Comment on it

    To get the date of the past day you can use the below code. You can pass any number of day for which you want to get date instead of 7, I'm getting date of past 7 days in the below example:

    /**
     * Get date before past 7 days
     * 
     * @return string
     */
    public static String findPast7DaysDate()
    {
        String sdf=null;
        try {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DATE,-7);
            sdf=new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").format(c.getTime());
            return sdf; 
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: