New Year Countdown Timer

Happy New Year Folks!

New Year Countdown Timer:

// Time Elapsed using System.currentTimeMillis()
// v1.1.1
// GLV 2023-12-31

// https://docs.oracle.com/javase/8/docs/api/java/util/GregorianCalendar.html
// https://www.timeanddate.com/counters/firstnewyear.html

import java.time.*;
import java.util.*;

long targetTime;
boolean flag;

void setup() 
  {
  size(1000, 200);
  
  textSize(96+16);
  textAlign(LEFT, CENTER);
  fill(255, 255, 0);
 
  //GregorianCalendar target =  new GregorianCalendar(year, month-1, day, hour, minute, second);
  GregorianCalendar target =  new GregorianCalendar(2024, 1-1, 1, 0, 0, 0);        // New years day at 00:00:00
  
  targetTime = target.getTimeInMillis();
  //println(targetTime);
  
  textAlign(CENTER, CENTER);
  }

void draw() 
  {
  background(0);  
  
  long timeRem = targetTime - System.currentTimeMillis();
  
  int days  = (int)(timeRem/(60*60*24*1000));
  int hrs   = (int)(timeRem/(60*60*1000));
  int mins  = (int)(timeRem/(60*1000));
  int secs  = (int)(timeRem/1000);
  int ms    = (int)(timeRem - secs*1000);
  
  if (timeRem < 1) flag = true;
  
  String timeString = nf(days, 3) +":"+ 
                      nf(hrs - days*24, 2) +":"+ 
                      nf(mins - hrs*60, 2) +":"+ 
                      nf(secs - mins*60, 2) +":"+ 
                      nf(ms, 3);  
  
  if (!flag)
    {
    text(timeString, width/2, height/2-15);
    println(timeString);  
    }
  else
    {
    String message = "Happy New Year!";
    fill(0, 255, 0);
    text(message, width/2, height/2-15);
    }
  }    

Modify code to countdown to 2025 New Years Day!

*GregorianCalendar target = new GregorianCalendar(2025, 1-1, 1, 0, 0, 0);*

:)

4 Likes