This tutorial will show how to make a simple java program that will count how many day there are till Christmas. The package being used to handle the dates is java.time . If you are unfamiliar with this package here is a quick intro on how to use the package.
The Christmas Count-down Clock code works like this. The today variable gets today’s date
Variable ChristmasDay is set to December 25 2020, which is this years Christmas.
Note that if Christmas has already past for this year, the Years() in java.time is given a 1 to represent Christmas being a Full year away from the current date.
Variable p gets the difference between today’s date and next years Christmas
import java.time.LocalDate;// importing LocalDate class
import java.time.Month;// importing Month class
import java.time.Period;// importing Period class
import java.time.temporal.ChronoUnit;// importing ChronoUnit class
public class aaa {
public static void main(String[] args) {
LocalDate today = LocalDate.now();//getting current date
LocalDate ChristmasDay = LocalDate.of(2020, Month.DECEMBER, 25);// setting Christmass day
LocalDate nextXmas = ChristmasDay.withYear(today.getYear());// Next year Christmas
//Add 1 if Christmas has past this year
if (nextXmas.isBefore(today) || nextXmas.isEqual(today)) {
nextXmas = nextXmas.plusYears(1);
}
Period p = Period.between(today, nextXmas);
long p2 = ChronoUnit.DAYS.between(today, nextXmas);// nanoseconds in days till Christmas
System.out.println("There are " + p.getMonths() + " months, and " +
p.getDays() + " days until Christmas! (" +
p2 + " total)");
}
}
Output :
There are 0 months, and 19 days until Christmas! (19 total)
Android Studio Loading Animation Between Activities
Progress Dialog is dialog showing a progress indicator and an optional text message or view. The methods of Progress Dialog being used in this tutorial are: ProgressDialog.setTitle() – Used to set title of dialog box ProgressDialog.setMessage() – Used to set dialog message being displayed ProgressDialog.setProgressStyle() – Choose the style of indicator ProgressDialog.dismiss() – Dismiss the…
Android Studio Tutorial SeekBar
SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch thumb and drag left or right to set the current progress level or various other task. In this example, the seekbar will be used to display a percentage. As the user moves the SeekBar left to right the percentage value…
Python Ethereum Block Chain Interaction with Web3
This tutorial will show how to interact with the Ethereum blockchain using Python. To start, the Python library Web3 will need to be installed. The Web3 library allows you to interact with a local or remote Ethereum node, using a HTTP or IPC connection. Using Web3 you will be able to create smart contracts on…