# Extracting current date and time

**URL:** https://discourse.processing.org/t/extracting-current-date-and-time/27754
**Category:** Coding Questions
**Created:** [February 12, 2021, 7:00am UTC](https://discourse.processing.org/t/extracting-current-date-and-time/27754 "2021-02-12T07:00:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![proc8888](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@proc8888](https://discourse.processing.org/u/proc8888)
#### Post date: [February 12, 2021, 7:00am UTC](https://discourse.processing.org/t/extracting-current-date-and-time/27754/1 "2021-02-12T07:00:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 12, 2021, 7:38am UTC](https://discourse.processing.org/t/extracting-current-date-and-time/27754/2 "2021-02-12T07:38:53Z")

</div>

You just concat the Strings using + and nf()

hour minute second

and

year month day

---

<div class="post-metadata">

### Author: ![stan47](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@stan47](https://discourse.processing.org/u/stan47)
#### Post date: [February 12, 2021, 9:32am UTC](https://discourse.processing.org/t/extracting-current-date-and-time/27754/3 "2021-02-12T09:32:14Z")

</div>

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);  
//}

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 13, 2021, 12:42pm UTC](https://discourse.processing.org/t/extracting-current-date-and-time/27754/4 "2021-02-13T12:42:34Z")

</div>

here

```auto
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); 

```
