Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script toLocaleDateString not work

I trying to run in GAS script

function test(){
var options = { year: 'numeric', month: 'long', day: 'numeric' },
locale="ru-RU",
data= (new Date()).toLocaleDateString(locale, options);

Browser.msgBox(data);
}

But google always return same format no matter what i type in locale.

How to fix this?

like image 508
Dmitrij Holkin Avatar asked Mar 12 '15 08:03

Dmitrij Holkin


2 Answers

If you want to do it server side you can use Utilities.formatDate().

var data = Utilities.formatDate(new Date(), "Europe/Moscow", "yyyy-MM-dd");

GAS formatDate() documentation

like image 65
Jorge Guillermo Negrete Avatar answered Nov 05 '22 00:11

Jorge Guillermo Negrete


Maybe Apps Script doesn't respond to the advanced parameters of toLocaleDateString(). If you are using HTML in your app, I'd try to make the conversion inside a script tag in the HTML, rather than in the server side .gs code.

like image 40
Alan Wells Avatar answered Nov 04 '22 23:11

Alan Wells