Timestamps & Timers

Notifications can be displayed with timestamps and timers (stopwatch & countdowns).

Timestamps

A timestamp can be set on the notification which can be used for sorting, and to visually show the user when the notification was delivered.

Set the showTimestamp value to true and a human friendly readable time will be shown. The example below will indicate to the user that the message was delivered 8 minutes ago:

notifee.displayNotification({
  title: 'Message from Sarah Lane',
  body: 'Tap to view your unread message from Sarah.',
  subtitle: 'Messages',
  android: {
    channelId,
    largeIcon: 'https://my-cdn/users/123.png',
    timestamp: Date.now() - 480000, // 8 minutes ago
    showTimestamp: true,
  },
});

The following would display a notification with a human readable time:

Loading...
Android Timestamp

Timers

In some cases, displaying an ongoing counting timer (a chronometer) alongside the notification can be useful. For example, for showing the ongoing time of a phone call.

To show a timer, set the showChronometer property on the notification options to true:

notifee.displayNotification({
  title: 'Message from Sarah Lane',
  body: 'Tap to view your unread message from Sarah.',
  subtitle: 'Messages',
  android: {
    channelId,
    largeIcon: 'https://my-cdn/users/123.png',
    timestamp: Date.now() - 480000, // 8 minutes ago
    showTimestamp: true,
    showChronometer: true,
  },
});
Loading...
Android Timer

If combined with a timestamp the timer will count positively/negatively from the specified time.

Timer direction

By default, the timer will count upwards to the time. To reverse the direction and count downwards, set the chronometerDirection to down:

notifee.displayNotification({
  title: '⭐ Claim Your Prize ⭐',
  body: 'Tap to claim your time limited prize! Hurry! ✨',
  subtitle: 'Prizes',
  android: {
    channelId,
    showChronometer: true,
    chronometerDirection: 'down',
    timestamp: Date.now() + 300000, // 5 minutes
  },
});

The following would display a notification with a countdown timer:

Loading...
Android Count Down Timer

Copyright 2020 - 2021 © Invertase Limited

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License and code samples are licensed under the Apache 2.0 License.

All product names, logos, and brands are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.