Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

################ 1.

Java 8 Innards - Date And Time API - Date


Manipulation################
import java.util.*;
class Solution
{
public static String manipulation(String stringInputDate, int days, int months,
int years) {
//Write your code here
String n;
int dd= Integer.parseInt(stringInputDate.split("-")[0]);
int mm= Integer.parseInt(stringInputDate.split("-")[1]);
int yy=Integer.parseInt(stringInputDate.split("-")[2]);
LocalDate d=LocalDate.of(yy,mm,dd);
d=d.plusDays(days);
d=d.plusMonths(months);
d=d.plusYears(years);
DateTimeFormatter f= DateTimeFormatter.ofPattern("dd-MM-yyyy");

return d.format(f).toString();
}
}
--------------------------------------------------------------------------------

m
------

er as
--------------------------------------------------------------------------------

co
------

eH w
################ 2. Java 8 Innards - Date And Time API - Temporal
Adjuster################

o.
import java.util.*; rs e
class TemporalAdjusterSolution
ou urc
{
public static String friendShipDay(int inputYear) {
//Write your code here
LocalDate d= LocalDate.of(inputYear,7,31);
o

LocalDate today=d.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
aC s

DateTimeFormatter f=DateTimeFormatter.ofPattern("dd-MM-yyyy");
v i y re

return today.format(f).toString();
}
}

--------------------------------------------------------------------------------
ed d

------
ar stu

--------------------------------------------------------------------------------
------
################3. Java 8 Innards - Date And Time API - Muharram
Month################
import java.util.*;
sh is

class MuharramMonthStartEnd {
public static String MuharramMonthStartDate(int inputYear) {
Th

//Write the code here


LocalDate d=LocalDate.of(inputYear,12,31);
HijrahDate h=
HijrahDate.from(d).with(ChronoField.DAY_OF_MONTH,1).with(ChronoField.MONTH_OF_YE
AR,1);
d=d.from(h);
DateTimeFormatter f=DateTimeFormatter.ofPattern("dd-MM-yyyy");
return d.format(f).toString();
}

public static String MuharramMonthEndDate(int inputYear, String


stringMuharramStart) {
//Write the code here
LocalDate d = LocalDate.of(inputYear,12,31);
HijrahDate h=
HijrahDate.from(d).with(ChronoField.DAY_OF_MONTH,1).with(ChronoField.MONTH_OF_YE

This study source was downloaded by 100000821315344 from CourseHero.com on 09-18-2021 16:11:41 GMT -05:00

https://www.coursehero.com/file/87135370/Java-8-Innards-Date-And-Time-APItxt/
AR,1);
d=d.from(h.with(TemporalAdjusters.lastDayOfMonth()));
DateTimeFormatter f= DateTimeFormatter.ofPattern("dd-MM-yyyy");
return d.format(f).toString();
}
}

--------------------------------------------------------------------------------
------
--------------------------------------------------------------------------------
------

################4. Java 8 Innards - Date And Time API - Zone Class


################
import java.util.*;
class Solution
{
public static String [] findingZonesInstant(String [] inputZones, int n, String
inputDateTime){
String stringInputDate=inputDateTime.split(" ")[0];
int yy=Integer.parseInt(stringInputDate.split("-")[0]);

m
int mmm=Integer.parseInt(stringInputDate.split("-")[1]);

er as
int dd=Integer.parseInt(stringInputDate.split("-")[2]);

co
String stringInputTime=inputDateTime.split(" ")[1];

eH w
int hh=Integer.parseInt(stringInputTime.split(":")[0]);
int mm=Integer.parseInt(stringInputTime.split(":")[1]);

o.
int ss=Integer.parseInt(stringInputTime.split(":")[2]);
rs e
LocalDateTime d=LocalDateTime.of(yy,mmm,dd,hh,mm,ss);
ou urc
ZonedDateTime zone=d.atZone(ZoneId.of("Asia/Kolkata"));
String []a=new String[n];
for(int i=0;i<n;i++)
{
o

ZonedDateTime z1=zone.withZoneSameInstant(ZoneId.of(inputZones[i]));
aC s

a[i]=z1.toString();
v i y re

}
return a;
}
}
ed d
ar stu
sh is
Th

This study source was downloaded by 100000821315344 from CourseHero.com on 09-18-2021 16:11:41 GMT -05:00

https://www.coursehero.com/file/87135370/Java-8-Innards-Date-And-Time-APItxt/
Powered by TCPDF (www.tcpdf.org)

You might also like