Monday 25 January 2021

Split Hour, Month separately from the date

Split Hour, Month separately from the date 

Groovy Script:

Date date = new Date();
println(date)// given date
Calendar calendar = Calendar.getInstance(); // creates a new calendar instance
def date1=calendar.setTime(date); // assigns calendar to given date
def time=calendar.get(Calendar.HOUR_OF_DAY); // gets hour in 24h format
println("time="+time)
def Time=calendar.get(Calendar.HOUR); // gets hour in 12h format
println("Time="+Time)
def month=calendar.get(Calendar.MONTH);
println("month="+month)
String a=time;
println("a="+a)
if(a=="6")
{
println("yes")
}
else
{
println("No")
}

Output:

12 ms

Mon Jan 25 15:43:58 UTC 2021

time=15

Time=3

month=0

a=15

No


1 comment:

  1. I’m not that much of an internet reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back down the road sap implemented companies in hyderabad

    ReplyDelete