Import the following package to work with Calendar class in Java, import java.util.Calendar;To display the entire day time, firstly create a Calendar object.Calendar cal = Calendar.getInstance();Display the entire date time using the fields shown below −// DATE Calendar.YEAR Calendar.MONTH Calendar.DATE // TIME Calendar.HOUR_OF_DAY Calendar.HOUR Calendar.MINUTE Calendar.SECOND Calendar.MILLISECONDThe following is the complete example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // current date and time System.out.println(cal.getTime().toString()); // date information System.out.println("Date Information.........."); System.out.println("Year = ... Read More
Create a Calendar object.Calendar cal = Calendar.getInstance();For using above Calendar class, do not forget to import the following package.import java.util.Calendar;Now, use the getTimeInMillis() method to get the time in milliseconds.cal.getTimeInMillis()The following is the final example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Milliseconds =" + cal.getTimeInMillis()); } }OutputMilliseconds =1542636999896
For using Calendar class, import the following package.import java.util.Calendar;Create a Calendar class object.Calendar cal = Calendar.getInstance();Now, get the week of month and year using the following fields.Calendar.WEEK_OF_MONTH Calendar.WEEK_OF_YEARThe following is an example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // current date and time System.out.println(cal.getTime().toString()); // date information System.out.println("Date Information.........."); System.out.println("Year = " + cal.get(Calendar.YEAR)); System.out.println("Month = " + (cal.get(Calendar.MONTH) + 1)); System.out.println("Date = " + ... Read More
The GregorianCalendar.isLeapYear() method determines if the given year is a leap year. Returns true if the given year is a leap year.Firstly, import the following package to work with GregorianCalendar class.import java.util.GregorianCalendar;Now, check for a year by adding it as a parameter in the isLeapYear() method.gcal.isLeapYear(2012)The following is an example.Example Live Demoimport java.text.ParseException; import java.util.GregorianCalendar; public class Demo { public static void main(String[] args) throws ParseException { GregorianCalendar gcal = new GregorianCalendar(); System.out.println("Is it a leap year? "+gcal.isLeapYear(2012)); } }OutputIs it a leap year? trueLet us see another example.Example Live Demoimport java.text.ParseException; import java.util.GregorianCalendar; ... Read More
The defined() function in PHP checks that constant exists or not.Syntaxdefined(name)Parametersname− The name of constant.ReturnThe defined() function returns true if the constant exists otherwise false.ExampleThe following is an example that checks whether a constant exist. Live DemoOutputThe following is the output.1
The die() function prints a message and exits the current script.Syntaxdie(msg)Parametersmsg − The message to write before exiting the script.ReturnThe die() function returns nothing.Example
To get the day of the week, use Calendar.DAY_OF_WEEK.Firstly, declare a calendar object and get the current date and time.Calendar calendar = Calendar.getInstance(); System.out.println(calendar.getTime().toString());Now, fetch the day of the week in an integer variable.int day = calendar.get(Calendar.DAY_OF_WEEK);The following is the final example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println(calendar.getTime().toString()); int day = calendar.get(Calendar.DAY_OF_WEEK); System.out.println("Day: " + day); int hour = calendar.get(Calendar.HOUR_OF_DAY); System.out.println("Hour: " + hour); int minute = ... Read More
The eval() function evaluates a string as PHP code.Syntaxeval(code)Parameterscode − The PHP code to be evaluated.ReturnThe eval() function returns null unless a return statement is called in the code string. Then the value passed to return is returned. if there is a parse error in the code string, eval() returns false.Example Live DemoOutputThe following is the output.This is $one $two! This is Demo text!
For using Calendar class, import the following package.import java.util.Calendar;Using the Calendar class, create an object.Calendar calendar = Calendar.getInstance();Now, create a string array of the day names.String[] days = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };Display the day name.days[calendar.get(Calendar.DAY_OF_WEEK) - 1]The following is the final example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Day: " + (calendar.get(Calendar.DATE))); System.out.println("Month: " + (calendar.get(Calendar.MONTH) + 1)); System.out.println("Year: " + (calendar.get(Calendar.YEAR))); String[] days = new String[] ... Read More
When you are attending an Interview, at some point in time, you can expect this question "Where do you see yourself in five years?”When a hiring manager asks you this, there will be quite a few things running through your head like "Moving up in the career", "That side of the table", "Working for myself", "Heading this Organization" etc., Why do they ask this question?The interviewer might want to understand more about your career goals and check whether you are motivated, proactive and like to stick around and check how this position would fit into your grand plan.How to answer ... Read More