Arie
Arie

Reputation: 41

how to format dates in non-english languages

How to format dates in google apps in other languages than English? The obvious function to use is Utilities.formatDate. However, no matter what the locale of the script or spreadsheet is set to, the result is always in English.

I've tried solutions where I put the (in my case Dutch) names of months and days into an array and offset into that. That sort of works.

However, if I put a string with a Dutch formatted date into a spreadsheet cell, Google quietely converts it back into a date value, which when I try to format it into something I can read brings me back to square one.

So, is there any definitive info on how to handle this. The most straightforward solution obviously would be if the Utilities.formatDate would accept a locale argument, or would actualy USE the locale set in the script or spreadsheetsettings.

Am I the only non-English developer with this problem?

Upvotes: 4

Views: 4539

Answers (2)

Avid
Avid

Reputation: 151

You need to use the language translation service, LanguageApp [0]. Here's how:

var date = Utilities.formatDate(new Date(), "PST", "MMMM d, yyyy");
var dutch = LanguageApp.translate(date, 'en', 'nl');
Logger.log(dutch);

[0]https://developers.google.com/apps-script/reference/language/language-app

Upvotes: 6

Jason Allshorn
Jason Allshorn

Reputation: 1625

For me I use the somewhat dated moment library for Appscript to format the date, and make sure the column I am adding data into is set to be text formatted not date formatted.

Upvotes: 0

Related Questions