Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing date/time/hour in email content/body in client/user time zone

I have web application written in Java. It uses Spring and Freemarker to make emails from templates and Spring JavaMailSender to send them.

I send emails that contain time in their content. The problem is that server stores time in UTC+00 time zone and clients may have different time zone like for example UTC+03. For example in email content there is 20/07/2017 11:30 (UTC+00), but recipient expects 20/07/2017 14:30 (UTC+03).

My question is: Is it possible to show time in email content in client time zone without having information about his time zone on the server side? Is there for example some trick that tells email client to interpret given time in his timezone?

like image 613
luke Avatar asked Jul 20 '17 13:07

luke


People also ask

How can you tell what time an email was sent?

Open the message in Inbox by Gmail. Hover the mouse cursor over the date shown in the header area. The full date and time will appear. To view the timestamp in the original message, click the three vertically stacked dots next to the date.

Does date now () depend on timezone?

Yes, Date. now() will give you the same UTC timestamp independent of your current timezone. Such a timestamp, rather a point in time, does not depend on timezones. The Java equivalent new Date() gives you the exact same thing.


1 Answers

My own answer after small research:

There is no "real solution" to show time in user timezone in an email without having information about his timezone in backend, but there are workarounds

Explanation:

  • All modern email clients filter out Javascript content so it is not possible to make a script which shows time with time shift based on client timezone.
  • There are no "magic tricks" to give email client a clue that some part of html contains time and it should be formatted in a proper way. Gmail, specifically, has no such feature.

Solution:

Store users timezones in backend (users to which we send emails).

Their timezones might be saved in two ways:

  • Statically - There is a place (an input) in which user specifies his timezone. For example at first logging in and/or in "settings" menu.
  • Dynamically - User timezone is obtained dynamically without his knowledge. For example after each logging in user timezone is obtained via Javascript, send to backend and saved in database.

Workarounds:

When for some reason you don't want to implement "real solution" there are some workarounds

  1. The simplest one is to show time with information about timezone next to it.
    For example 20/07/2017 11:30 gives insufficient information, because we don't know the timezone, but 20/07/2017 11:30 (UTC+03) gives all the information that user needs. If he wants time in his own timezone he just have to do the math on his own.

  2. A little bit sophisticated practice is to provide a link to web page which shows time in client timezone and gets time in parameters.
    For example:
    https://some-time-resolving-service.com/time/20-07-2017/11/30
    checks client timezone using Javascript and shows website with time based on parameters and his timezone.
    There are services on the Internet that provide such feature. For example https://www.timeanddate.com/worldclock/ which is used for by slack team on their status site to show time of incidents, outages etc. in reader timezone. Example: https://www.timeanddate.com/worldclock/fixedtime.html?iso=20181108T0035&p1=224 which I took from this incident: https://status.slack.com/2018-11/8abae7811317864c.

  3. Do the same as in the second point, but instead of providing link embed an image and use a service which returns an image.
    Like that:
    <img src="https://some-time-resolving-service.com/timeimage/20-07-2017/11/30" alt="Time in the right timezone" height="50" width="100">
    or like that:
    <img src="https://some-time-resolving-service.com/timeimages/20-07-2017-11-30.png" alt="Time in the right timezone" height="50" width="100">.
    I am not sure if it works.
like image 66
luke Avatar answered Sep 20 '22 16:09

luke