Showing posts with label Date. Show all posts
Showing posts with label Date. Show all posts

Wednesday, January 11, 2017

How to get current week date range and previous week date range using JodaTime .

Here is Joda time Maven dependency.
<dependency>
                                                <groupId>com.fasterxml.jackson.datatype</groupId>
                                                <artifactId>jackson-datatype-joda</artifactId>
                                                <version>2.8.1</version>
                                </dependency>

Below program you can find out current and previous week date range.

package swain.swain;

import java.util.Date;

import org.joda.time.LocalDate;

public class DataUtill {

    public static void main(String[] args) {
         int currentWeekDay = LocalDate.now().getDayOfWeek();
         int startOfWeekInterval = (currentWeekDay - 1) * -1;
         int endOfWeekInterval = 6 - currentWeekDay;
         if (endOfWeekInterval < 0) {
             endOfWeekInterval = 0;
         }
         Date fromDate = LocalDate.now().plusDays(startOfWeekInterval).toDate();
         Date thruDate = LocalDate.now().plusDays(endOfWeekInterval).toDate();

         System.out.println("Current Week From date:" + fromDate);
         System.out.println("Current Week To date:" + thruDate);

         Date preFromDate = LocalDate.now().minusWeeks(1).withDayOfWeek(1).toDate();
         Date preToDate = LocalDate.now().minusWeeks(1).withDayOfWeek(1).plusDays(6).toDate();

         System.out.println("Previous Week From date:" + preFromDate);
         System.out.println("Previuos Week To date:" + preToDate);

    }
}


OutPut.

Current Week From date:Mon Jan 09 00:00:00 IST 2017
Current Week To date:Sat Jan 14 00:00:00 IST 2017
Previous Week From date:Mon Jan 02 00:00:00 IST 2017

Previuos Week To date:Sun Jan 08 00:00:00 IST 2017

Thursday, June 13, 2013

how to get after 5 days date

Calendar currentDate = Calendar.getInstance();
        Calendar prevDay = (Calendar) currentDate.clone();
        prevDay.add (Calendar.DAY_OF_YEAR, 5);
        System.out.println ("After 5 Day: " + prevDay.getTime());

How to get previous 7 day Date

Calendar currentDate = Calendar.getInstance();
        Calendar prevDay = (Calendar) currentDate.clone();
        prevDay.add (Calendar.DAY_OF_YEAR, -7);
        System.out.println ("Previous 7 Day: " + prevDay.getTime());

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...