Extracting current date and time

How do I extract current date and current time?
The ‘Time & Date’ functions in Processing org reference (online) has individual fields for year, month, day, hour etc.
Instead, I would like to extract the whole current date(YYYYMMDD) into one variable and the current time (HMS) into another field.
Thanks for any tips.

You just concat the Strings using + and nf()

hour minute second

and

year month day

1 Like

This may help I hope

import java.util.*;
void setup(){
Calendar now = Calendar.getInstance();
println( String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now));
println( String.format("%1$ty%1$tm%1$td", now));
println( String.format("%1$tH%1$tM%1$tS", now));

}
void draw(){}
// if you need a function…
//String timestamp() {
//Calendar now = Calendar.getInstance();
//return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
//}

1 Like

here

String dateMy, timeMy="";

dateMy = nf(year(), 4)+"/"
  +nf(month(), 2)+"/"
  +nf(day(), 2); 

timeMy= nf(hour(), 2)+":"
  +nf(minute(), 2)+":"
  +nf(second(), 2);

println (dateMy, timeMy); 

1 Like