Determine Day of Week in Month from Gregorian Calendar in Java

Samual Sam
Updated on 26-Jun-2020 08:35:26

320 Views

To work with the GregorianCalendar class, import the following package −import java.util.GregorianCalendar;To get the day of week in month, use the following field −cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)Above, cal is the GregorianCalendar object we created before −GregorianCalendar cal = new GregorianCalendar();The following is an example −Example Live Demoimport java.util.GregorianCalendar; import java.util.Calendar; import java.util.Date; public class Demo {    public static void main(String[] args) {       GregorianCalendar cal = new GregorianCalendar();       // 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

Static Functions in C

Samual Sam
Updated on 26-Jun-2020 08:34:44

21K+ Views

A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as static function by placing the static keyword before the function name.An example that demonstrates this is given as follows −There are two files first_file.c and second_file.c. The contents of these files are given as follows −Contents of first_file.cstatic void staticFunc(void) {    printf("Inside the static function staticFunc() "); }Contents of second_file.cint main() {    staticFunc();    return 0; }Now, if the above ... Read More

Display Weekday Names in Java

karthikeya Boyini
Updated on 26-Jun-2020 08:34:35

483 Views

To display weekday names in Java, use the getWeekdays() method.For that, firstly import the following package.import java.text.DateFormatSymbols;Now, create a string array and get all the weekday names using the getWeekdays() method.String[] weekDays = new DateFormatSymbols().getWeekdays();Example Live Demoimport java.text.DateFormatSymbols; public class Demo {    public static void main(String[] args) {       String[] weekDays = new DateFormatSymbols().getWeekdays();       System.out.println("Weekday names...");       for(String days: weekDays){       System.out.println(days);    } } }OutputWeekday names... Sunday Monday Tuesday Wednesday Thursday Friday Saturday

Format and Parse Date in Java

Samual Sam
Updated on 26-Jun-2020 08:33:29

319 Views

To format a date in Java, firstly import the following package.import java.text.DateFormat;Now, create DateFormat object.DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);Use the format() method to format the above dates.System.out.println(shortFormat.format(new Date())); System.out.println(longFormat.format(new Date()));To parse the dates, use the parse() method.Example Live Demoimport java.text.DateFormat; import java.text.ParseException; import java.util.Date; public class Demo {    public static void main(String[] args) throws Exception {       // format date       DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);       DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);       System.out.println("Format Date...");       System.out.println(shortFormat.format(new Date()));       System.out.println(longFormat.format(new Date()));       // parse date ... Read More

Pow Function in C

karthikeya Boyini
Updated on 26-Jun-2020 08:33:04

7K+ Views

The function pow() is used to calculate the power raised to the base value. It takes two arguments. It returns the power raised to the base value. It is declared in “math.h” header file.Here is the syntax of pow() in C language, double pow(double val1, double val2);Here, val1 − The base value whose power is to be calculated.val2 − The power value.Here is an example of pow() in C language, Example#include #include int main() {    double x = 5.5;    double y = 4.0;    double p;    p = pow(x, y);    printf("The value : %lf", p);   ... Read More

Default Values of Static Variables in C

Samual Sam
Updated on 26-Jun-2020 08:31:52

4K+ Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name.Static variables are initialized only once. Compiler persist the variable till the end of the program. Static variable can be defined inside or outside the function. They are local to the block. The default value of static variable is zero. The static variables are alive till the execution of the program.Here is the syntax of static variables in C language, static datatype variable_name;Here, datatype − The datatype ... Read More

Return Type of getchar, fgetc, and getc in C

karthikeya Boyini
Updated on 26-Jun-2020 08:30:45

2K+ Views

Details about getchar(), fgetc() and getc() functions in C programming are given as follows −The getchar() functionThe getchar() function obtains a character from stdin. It returns the character that was read in the form of an integer or EOF if an error occurs.A program that demonstrates this is as follows −Example Live Demo#include int main (){    int i;    printf("Enter a character: ");    i = getchar();    printf("The character entered is: ");    putchar(i);    return(0); }OutputThe output of the above program is as follows −Enter a character: G The character entered is: GNow ... Read More

Return Values of printf and scanf in C

Samual Sam
Updated on 26-Jun-2020 08:25:18

12K+ Views

The printf() and scanf() functions are required for output and input respectively in C. Both of these functions are library functions and are defined in the stdio.h header file.Details about the return values of the printf() and scanf() functions are given as follows −The printf() functionThe printf() function is used for printing the output. It returns the number of characters that are printed. If there is some error then it returns a negative value.A program that demonstrates this is as follows −Example Live Demo#include int main(){    char str[] = "THE SKY IS BLUE";    printf("The value returned ... Read More

Return Date Set to First Millisecond of the Day After Midnight in Java

Samual Sam
Updated on 26-Jun-2020 08:24:18

132 Views

Let us first set the calendar object.Calendar calendar = Calendar.getInstance();Use the getMinimum() method in Java to return the minimum value for the given calendar field. We will use it to set the minute, hours second and milliseconds.For hour and minute.calendar.set(Calendar.HOUR_OF_DAY, calendar.getMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE));For second and milliseconds.// second calendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND)); // millisecond calendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND));The following is an example that returns a Date set to the first possible millisecond of the day after midnight.Example Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] argv) throws Exception {       Calendar calendar = Calendar.getInstance();       // ... Read More

Return Date Set to Last Millisecond of the Day Before Midnight in Java

karthikeya Boyini
Updated on 26-Jun-2020 08:23:20

158 Views

Let us first set the calendar object.Calendar calendar = Calendar.getInstance();Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, hours second and milliseconds.For hour and minute.calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));For second and milliseconds.// second calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); // millisecond calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));The following is an example that returns a Date set to the last possible millisecond of the day before midnight.Example Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] argv) throws Exception {       Calendar calendar = Calendar.getInstance();       // ... Read More

Advertisements