Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

calculate number of years months and days between two dates in java

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
Date birth = sdf.parse("2000-01-01");
Date now = new Date(System.currentTimeMillis());
		
Calendar c = Calendar.getInstance();
c.setTimeInMillis(now.getTime() - birth.getTime());
int y = c.get(Calendar.YEAR)-1970;
int m = c.get(Calendar.MONTH);
int d = c.get(Calendar.DAY_OF_MONTH)-1;
Comment

Calculate weeks from date using java

SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
String classStartData = "31 01 2021";
String classEndData = "08 03 2021";

Date dateClassStart = myFormat.parse(classStartData);
Date dateClassEnd = myFormat.parse(classEndData);

long differenceWeek = dateClassEnd.getTime() - dateClassStart.getTime();
int programLength = (int)(TimeUnit.DAYS.convert(differenceWeek, TimeUnit.MILLISECONDS)/7);
System.out.println("Class length in weeks: " +programLength);
Comment

PREVIOUS NEXT
Code Example
Java :: java final method 
Java :: Java find duplicate items 
Java :: java or cpp 
Java :: extract html tag using regex 
Java :: convert python code to java 
Java :: Linked list implementation in Java source code 
Java :: lombok 
Java :: log4j2.properties file need to save in spring boot application 
Java :: Java Program to find the perimeter of the circle 
Java :: biginteger modulo in java 
Java :: how to change my file into binary data using java 
Java :: Java Enum ordinal() 
Java :: client missing intents 
Java :: java non-breajubg soace remove 
Java :: jbutton 
Sql :: mysql show users 
Sql :: postgresql reset sequence 
Sql :: oracle sql drop sequence 
Sql :: postgresql server restart 
Sql :: sql server find columns list in tables 
Sql :: mysql list databases 
Sql :: alter table column size oracle 
Sql :: mysql database stopped xampp mac 
Sql :: set mysql mode global query 
Sql :: RENAME table pl sql 
Sql :: wordpress sql find and replace 
Sql :: mysql group by day 
Sql :: mysql timestamp in laravel migration 
Sql :: alter sequence postgres 
Sql :: sql count duplicate rows 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =