Java Today getTodayAsSecond()

Here you can find the source of getTodayAsSecond()

Description

get Today As Second

License

Open Source License

Declaration

public static String getTodayAsSecond() 

Method Source Code

//package com.java2s;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String getTodayAsSecond() {
        return getTodayAsSecond(0);
    }/*from  w ww  .ja va  2  s  .  c o  m*/

    /**
     * Gets today as second.
     *
     * @return the today as second
     */
    public static String getTodayAsSecond(int d) {
        String result = "0";
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.add(Calendar.DAY_OF_YEAR, d);
            Date date = df.parse(df.format(calendar.getTime()));
            calendar.setTime(date);
            result = Long.toString(calendar.getTimeInMillis() / 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. getToday(String datePattern)
  2. getToday(String format)
  3. getToday(String formatString)
  4. getToday(String time)
  5. getTodayAsLong()
  6. getTodayDate()
  7. getTodayDate()
  8. getTodayDate()
  9. getTodayDateAsString()