date()


Description

Gets the current date and time from RTC of PHPoC Shield for Arduino.

Syntax

datetime.date()
datetime.date(format)

Parameters

format - time format

Format Description
Y A full numeric representation of a year, 4 digits (example: 2016)
y A two digit representation of a year (example: 16)
M A short texture representation of a month, three letters (example: Mar)
m Numeric representation of a month with leading zeros (example: 03)
n Numeric representation of a month without leading zeros (example: 3)
d Day of the month, 2 digits with leading zeros (01 to 31)
j Day of the month without leading zeros (1 to 31)
D A textual representation of a day, three letters (example: Mon)
g 12-hour format of an hour without leading zeros (1 to 12)
G 24-hour format of an hour without leading zeros (0 to 23)
h 12-hour format of an hour with leading zeros (01 to 12)
H 24-hour format of an hour with leading zeros (00 to 23)
i Minutes with leading zeros (00 to 59)
s Seconds with leading zeros (00 to 59)
a Lowercase Ante meridiem and Post meridiem (am or pm)
A Uppercase Ante meridiem and Post meridiem (AM or PM)

Returns

With a given format, it returns a formatted string represents the current date and time.
Without a given format, it returns a string with the last given format.
The default format is "D M j H:i:s".

Example

#include <SPI.h>
#include <Phpoc.h>

PhpocDateTime datetime;

void setup() {
  Serial.begin(9600);
  while(!Serial)
    ;

  Phpoc.begin();

  Serial.println("Phpoc Time test");

  Serial.print(datetime.year());
  Serial.print('-');
  Serial.print(datetime.month());
  Serial.print('-');
  Serial.print(datetime.day());
  Serial.print(' ');
  Serial.print(datetime.dayofWeek());
  Serial.print(':');
  Serial.print(datetime.hour());
  Serial.print(':');
  Serial.print(datetime.minute());
  Serial.print(':');
  Serial.print(datetime.second());
  Serial.println();

  datetime.date("Y-m-d H:i:s");
}

void loop() {
  Serial.println(datetime.date());
  delay(1000);
}