Compare Two Dates Along with Time in Java

Maruthi Krishna
Updated on 06-Feb-2021 03:47:06

902 Views

The java.time.LocalDateTime class represents the local date and time i.e. the date without time zone, you can use this object instead of Date. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two dates −ExampleLive Demoimport java.time.LocalDateTime; public class Test {    public static void main(String args[]) {         LocalDateTime dateTime1 = LocalDateTime.of(2007, 11, 25, 10, 15, 45);       LocalDateTime dateTime2 = LocalDateTime.of(1999, 9, 12, 07, 25, 55);             Boolean bool1 = dateTime1.isAfter(dateTime2);         Boolean bool2 = dateTime1.isBefore(dateTime2);       Boolean bool3 = ... Read More

Format Date String Using SimpleDateFormat in Java

Maruthi Krishna
Updated on 06-Feb-2021 03:45:39

300 Views

One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat class. To parse/convert a string as a Date object −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample {    public static void main(String args[]) throws ParseException {         String date_string = "2007-25-06";       //Instantiating the SimpleDateFormat class       SimpleDateFormat formatter = new SimpleDateFormat("yyyy-dd-MM");             //Parsing the given String to Date object       Date ... Read More

Create Date Object from String Value in Java

Maruthi Krishna
Updated on 06-Feb-2021 03:45:19

2K+ Views

Using the SimpleDateFormat classOne of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat class. To parse/convert a string as a Date object −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample {    public static void main(String args[]) throws ParseException {         String date_string = "2007-25-06";       //Instantiating the SimpleDateFormat class       SimpleDateFormat formatter = new SimpleDateFormat("yyyy-dd-MM");             //Parsing the given String to Date object   ... Read More

Tim Sort Algorithm in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:59:11

2K+ Views

The Timsort is a stable sorting algorithm that uses the idea of merge sort and insertion sort. It can also be called as a hybrid algorithm of insertion and merge sort. It is widely used in Java, Python, C, and C++ inbuilt sort algorithms. The idea behind this algorithm is to sort small chunks using insertion sort and then merge all the big chunks using the merge function of the merge sort algorithm.WorkingIn this algorithm, the array is divided into small chunks. The chunks are known as RUN. Each RUN is taken and sorted using the insertion sort technique. After ... Read More

Delannoy Numbers: Write a Program in C++ to Find the Delannoy Number

Dev Prakash Sharma
Updated on 05-Feb-2021 12:58:37

241 Views

Delannoy Numbers − A Delannoy number D describes the number of paths from the southwest corner(0, 0) to northeast corner(a, b) in a rectangular grid using only allowed steps east ( →), northeast ( ↗ ) and north ( ↑ ).Thus, we can say that a recurrence relation is, D(a, b) = D(a-1, b) + D(a, b-1) + D(a-1, b-1) where D(0, 0)=1.For example, the Delannoy number D(3, 3) equals 63.Algorithm to find the Delannoy NumberTake two coordinates (a, b) as Input.An Integer function generateDelannoy(int a, int b) which takes coordinates ‘a’ and ‘b’ as input.In the base case, we ... Read More

Validate IPv6 Address Using Regex Patterns in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:57:54

2K+ Views

Given an IP Address, the task is to validate this IP address and check whether it is IPv6 or not with the help of ReGex(Regular Expression). If the IP Address is valid then print “IPv6 Address” otherwise print “Not”.A valid IPv4 address is an IP in the form "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX" where each Xi digit is a hexadecimal digit. For example, Input-1 −IP= “3001:0da8:82a3:0:0:8B2E:0270:7224”Output −“Not”Explanation − This is not a valid IPv6 address, return “Not”.Input-2 −IP= “2001:0db8:85a3:0000:0000:8a2e:0370:7334”Output −“IPv6”Explanation − This is a valid IPv6 Address, return “IPv6”.Approach to solve this problemTo check whether the given IP address is IPv6 or not, we ... Read More

Validate IPv4 Address Using Regex Patterns in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:57:29

2K+ Views

Given an IP Address, the task is to validate this IP address and check whether it is IPv4 or not with the help of ReGex(Regular Expression). If the IP Address is valid then print “IPv4 Address” otherwise print “Not”.A valid IPv4 address is an IP in the form "X1.X2.X3.X4" where 0

Valid Sudoku in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:57:03

3K+ Views

Let’s suppose we’ve given a 9×9 matrix called a Sudoku. The task is to check whether the given Sudoku Pattern is valid or not.In general, a Sudoku board look like this, Rules of Sudoku −Every row contains a number in the range 1-9Every column contains numbers in the range 1-9.Each block of 3×3 contains unique numbers in it.A particular row cannot have the same number.A particular column cannot have the same number.For ExampleInput-1 −sudoku[]=    [["3", "5", ".", ".", "2", ".", ".", ".", "."]    , ["7", ".", ".", "1", "6", "5", ".", ".", "."]    , [".", "9", "8", ... Read More

Update the Bit in Given Position of a Number Using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:56:21

2K+ Views

In the given problem, we have to update the bit of the given index of a number. To update the number, we can use Bit Manipulation operation on a given number. For example, Input-1 −N= 25 bit= 1 position= 2Output −29Explanation − Since the given input 25 can be written in binary as ‘11001’ whereas the position index is ‘2’ and the bit is ‘1’. After replacing the digits at the given position the output will be ‘11101’ which is equivalent to ‘29’.Approach to solve this problemIn the given position or index of a number, the task is to update ... Read More

Static Assert in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:55:01

413 Views

static_assert is a function which is useful for programmers to print the error in the screen after compiling the program without messing up with the output too much.Earlier in C++11 and C++14, static_assert had different functionality which means we have to write our own message while defining the static_assert. However, In C++ 17 static_assert can be invoked without passing the message.It is compatible with other asserts libraries functions like BOOST_STATIC_ASSERT as well.Syntax{    auto __range= For-range-Intializer;    auto __begin= begin-expression;    auto __end= end-expression;    for(; __begin!= __end; ++__begin){       range-declaration= *__begin;       statement    } ... Read More

Advertisements