get Current Week Day Start Time - Android java.util

Android examples for java.util:Day

Description

get Current Week Day Start Time

Demo Code


//package com.java2s;

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

public class Main {

    private final static SimpleDateFormat shortSdf = new SimpleDateFormat(
            "yyyy-MM-dd");
    private final static SimpleDateFormat longSdf = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");

    public static Date getCurrentWeekDayStartTime() {
        Calendar c = Calendar.getInstance();
        try {/*from  w w  w.  ja v a 2s .com*/
            int weekday = c.get(Calendar.DAY_OF_WEEK) - 2;
            c.add(Calendar.DATE, -weekday);
            c.setTime(longSdf.parse(shortSdf.format(c.getTime())
                    + " 00:00:00"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return c.getTime();
    }
}

Related Tutorials