Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3189

Re: how to calculate week

$
0
0

use this

 

import java.text.SimpleDateFormat;

import java.util.Date;

public class HelloWorld {

  public static void main(String[] args) throws Exception {

    SimpleDateFormat formater=new SimpleDateFormat("yyyy-MM-dd");

 

 

long d1=formater.parse("2015-08-01").getTime();

long d2=formater.parse("2015-08-19").getTime();

 

 

int days = (int)Math.abs((d1-d2)/(1000*60*60*24)); // suppose 9 days

 

 

int number_of_weeks = (int)Math.ceil(days/7);

 

 

System.out.println(number_of_weeks); // use result.addValue() here

  }

}

 

 

gives the week number as 2 if it has 14 to 20 days

 

if you want the celing value just give days/7.0 it will give the rounded up value


Viewing all articles
Browse latest Browse all 3189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>