首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Applescript更改日期格式

Applescript更改日期格式
EN

Stack Overflow用户
提问于 2021-03-29 13:13:48
回答 2查看 1.1K关注 0票数 1

我希望有人能帮我把这个苹果脚本格式化为MM/DD/YY或至少短日期格式。我对此有一点了解,但就脚本编写和变量识别而言,我太过头了。

我正在运行附加的脚本来将我当前的Safari添加到Things (ToDoList应用程序)

https://gist.githubusercontent.com/cdzombak/b93ce2c0dca0f53a0cbcc29784882dfd/raw/2cb3b9c3f616c2c883079e9b84225fca343255e0/Safari%20Tab%20List%20to%20Things.scpt

它运行的很好,但我想缩短日期。

我的假设是,我需要在定义变量的脚本顶部进行更改。

代码语言:javascript
运行
复制
-- SET DATE STAMP
set the dateStamp to ((the current date) as string)
set noteTitle to "URL List from Safari Tabs on " & the dateStamp

最后一行看起来像现场,但我不知道要更改什么或如何格式化它。

EN

Stack Overflow用户

回答已采纳

发布于 2021-03-29 13:58:10

你给了提示:至少短日期格式

代码语言:javascript
运行
复制
set dateStamp to short date string of (current date)

特定的字符串格式取决于当前的区域设置。

更通用的是shell的date命令

代码语言:javascript
运行
复制
set dateStamp to do shell script "/bin/date +%D"

返回MM/DD/YY。

或者你可以使用AppleScriptObjC

代码语言:javascript
运行
复制
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

set dateFormatter to current application's NSDateFormatter's new()
set dateFormatter's locale to current application's NSLocale's localeWithLocaleIdentifier:"us_EN_POSIX"
set dateFormatter's dateFormat to "MM/dd/yyyy"
set dateStamp to (dateFormatter's stringFromDate:(current date)) as text
票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66854889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档