In this article, we will discuss how to display the two-digit month. A two-digit month ensures that even the first month (i.e., January) is formatted to display as 01 instead of 1. This formatting provides a consistent two-digit representation for all months. To Display two-digit month in Java is quite easy. Let us learn the following ways: Displaying Two-Digit Month Using the "%tm" Specifier To retrieve a two-digit month from a given date, we can use the "%tm" specifier. This format specifier is used with the printf() method to display the month of a date as a two-digit number. Example ... Read More
Sometimes while working with with dates in JavaScript, it is common to need specific dates for calculations or validations. In this problem, we are given a date in the form of year-month-date and we have to subtract one month from it. In this article, we are going to learn how we can subtract one month from a given date using Moment.JS. Prerequisite Moment.js: Moment.js is a popular JavaScript library used for dealing with dates. This library is used to modify, parse, validate, manipulate, and display dates and times in JavaScript. Install Moment.js We ... Read More
Sometimes while working with dates and times, we need to manipulate or normalize them to a specific time. One such common need is to reset a date's time to the start of the day, i.e. 00:00:00 midnight. In this article, we are going to learn different approaches to set the time to 00:00:00 using Moment.js. Prerequisite Moment.js: Moment.js is a popular JavaScript library used to deal with dates. This library is used to modify, parse, validate, manipulate, and display dates and times in JavaScript. Install Moment.js We ... Read More
In this article, we will learn how to copy text to the clipboard in ReactJS. There are two most commonly used methods: the copy-to-clipboard package and the Clipboard API. The copy-to-clipboard package provides a copy() function that allows us to copy text. The Clipboard API is a web browser API that also provides a few functions for clipboard interaction, including copying text. Prerequisites Installed npm ReactJS useState hook Approaches to Copy Text to Clipboard There are two primary approaches to copying text to the clipboard in ReactJS: ... Read More
Suppose we have an array, and we need to check whether each element has a unique number of occurrences. If no such element exists, we return false; otherwise, we return true. For example, given the array [1, 1, 2, 2, 2, 3, 4, 4, 4, 4], the function will return true because no two elements have the same number of occurrences: 1 occurs twice, 2 occurs three times, 3 occurs once, and 4 occurs four times. Various Techniques to Find Unique Occurrences Following are the various techniques to find the unique occurrence of the elements in a list − ... Read More
The int main Function The int main function indicates that the program returns an integer value, typically 0, at the end of its execution. A return value of 0 signifies that the program has been executed successfully. The syntax of int main is as follows − int main(){ --- --- return 0; } Example Below is a C program for the int main() function without arguments. It uses recursion to decrement a static variable a from 10 to 0, printing its value after each decrement. The main function calls itself until a reaches 0, then returns 0. #include ... Read More
In this article, we will learn to create a program to check both horizontal and vertical symmetry in a binary matrix in JavaScript. A binary matrix is a 2-D array that consists of one and zero only as the elements in each cell. Horizontal symmetry of a binary matrix means if the first row is the same as the last row, the second row is the same as the second last row, and so on. What are symmetry matrices? Symmetry in matrices refers to how the values in the matrix mirror themselves along an axis. In the case of a ... Read More
In this article, we will learn to extract the maximum numeric value from a string using Java’s regex. While Java provides several ways to handle string manipulation, regular expressions (regex) offer a powerful and efficient tool for such tasks. Problem Statement The maximum numeric value is extracted from an alphanumeric string. An example of this is given as follows − Input String = abcd657efgh234 Output Maximum numeric value = 657 Using Java Regex and Pattern Class Java provides the Pattern and Matcher classes to work with regular expressions. The Pattern class compiles a regular expression, and the Matcher class is ... Read More
Make CSS Vertical Align Property Work on Element
This article will let you understand the vertical-align property in CSS. Here, we discuss the limitations of the vertical-align property and a few methods to overcome this, and hence, you will learn the solution to make the vertical-align property work on a div tag. Why does vertical-align don't work on div elements? Remember, the `vertical-align` property only works on inline, inline-block, and table-cell elements. You cannot use it to align block-level elements vertically. Tables work differently than divs because all the rows in a table are the same height. If a cell doesn’t have much content, the browser ... Read More
This article will let you understand the vertical-align property in CSS. Here, we discuss the limitations of the vertical-align property and a few methods to overcome this, and hence, you will learn the solution to make the vertical-align property work on a div tag. Why does vertical-align don't work on div elements? Remember, the `vertical-align` property only works on inline, inline-block, and table-cell elements. You cannot use it to align block-level elements vertically. Tables work differently than divs because all the rows in a table are the same height. If a cell doesn’t have much content, the browser ... Read More
Sometimes while working with with dates in JavaScript, it is common to need specific dates for calculations or validations. One such situation is when we are given a date and we have to determine the last day of the previous month. In this article, we are going to learn how we can last day of the Previous Month from Date in Moment.js. Prerequisite Moment.js: Moment.js is a popular JavaScript library used to deal with dates. This library is used to modify, parse, validate, manipulate, and display dates and times in JavaScript. We can install the Moment.js library in ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP