如何在Google Apps脚本中使用momentsjs? [英] How do I use momentsjs in Google Apps Script?

查看:106
本文介绍了如何在Google Apps脚本中使用momentsjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Google Apps Script中使用momentjs库,但我不清楚如何操作。我不知道如何添加库,所以显然运行如下结果在参考错误:'时刻'未定义:

I'm trying to utilize the momentjs library in Google Apps Script but I'm not clear on how to do so. I'm not sure how to add the library, so obviously running something like the following results in "Reference Error: 'moment' is not defined":

var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
var difference = a.diff(b);


推荐答案

使用外部Javascript库并不那么容易...根据你想要使用它的上下文(一个嵌入文档的脚本文件的web应用程序),这种方法会有所不同。

Using external Javascript library is not so easy... Depending on the context in which you want to use it (a webapp of a document embedded script) the approach will be different.

我没有在客户端JavaScript中尝试它我不确定caja会允许它,但我发现这篇文章展示了一种用户可以使用Google Script Library 将其包含的可能方式,如果我阅读帖子,它似乎可以正常工作......

I didn't try it in client JavaScript and I'm not sure caja will allow it but I found this post that shows a possible way to include it using a Google Script Library that a user has build and if I read the post it seems to work...

用户是Google开发者,因此他确切知道他在说什么;)如果它适合您,请在此更新。

The "user" is a Google developper so he knows for sure what he is talking about ;) please update here if it worked for you.

这篇关于如何在Google Apps脚本中使用momentsjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆