9

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?

luke
  • 3,435
  • 33
  • 41
  • The first answer in this might help... . https://stackoverflow.com/questions/9543580/javascript-time-zones-and-daylight-savings-time You'll have to embed javascript into the email to make it work, though. – MarkBowman Jul 20 '17 at 15:16
  • 1
    Embedding javascript is not an option, because every modern email client filters out javascript scripts. In case of my app users will use mostly **Gmail**. I tried to embed javascript scripts in mails and gmail prevented from executing them by ignoring `` tags. Any other ideas? Maybe **Gmail** web client interprets some html tags or specifically formatted strings as time/hour and automatically adds client time zone to them? – luke Jul 20 '17 at 17:04
  • I dont think there is but if you use PHP and display the time then you can add the time as image. The time will have to be dynamic, meaning if the user opens it after a few hours the time will change. – Syfer Jul 21 '17 at 09:35
  • Could you give me some article/tutorial/code sample of this solution? Or link to service which returns generated image with time based on url parameters. – luke Jul 25 '17 at 06:36

1 Answers1

16

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.
nak
  • 690
  • 6
  • 15
luke
  • 3,435
  • 33
  • 41
  • 3
    So looks like there is no solution. Saving at back-end is not reliable as the user might be in traveling or just finished his trip and back to home. We need the time zone at the place and the instant he looks at our interface. So I would go with mentioning UTC, although I do not like it. – Sravan May 16 '19 at 19:55