Atom 编辑器:插入时间戳的片段 [英] Atom editor: snippet for inserting a timestamp

查看:39
本文介绍了Atom 编辑器:插入时间戳的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我正在使用的 Atom 片段.我想要做的是在最后插入一个带有开发人员姓名的时间戳.当多人在同一个代码库上工作并且您需要注释掉一些代码或添加注释时,这很有用.这样其他开发人员就知道谁做了什么,什么时候做了.我发现它非常有用,并想创建一个片段来执行此操作.

Below is an Atom snippet I was playing with. What I want to do is insert a timestamp with a developer's name at the end. This is useful when multiple folks are working on the same codebase and you need to comment out some code or add a comment. This way other developers know who did what, and when they did it. I've found it very useful and wanted to create a snippet to do this.

然而,正如你从代码片段中看到的,它非常难看……JS 不是我的强项.有没有干净的方法来做到这一点?

However, as you can see from the snippet, it's very ugly...JS is not my forte. Is there a clean way to do this?

time => tab => YYYY-MM-DD HH:MM/NAME

time => tab => YYYY-MM-DD HH:MM / NAME

'.source':
  'Timestamp':
    'prefix': 'time'
    'body': """
      # #{datetime = new Date(); datetime.getFullYear()}-#{(datetime.getMonth()+1)}-#{datetime.getDate()} #{datetime.getHours()}:#{datetime.getMinutes()} / NAME
    """

推荐答案

最接近的方法是使用 toISOString()

new Date().toISOString()

这将打印这样的日期:

2014-09-05T07:15:14.840Z

缺点是这将始终以 UTC 格式打印日期.

The downside is that this will always print the date in UTC.

此处列出了更多选项:如何格式化 JavaScript 日期 - 也许你会在那里看到一些东西.根据对答案的快速浏览,您所做的实际上看起来不错.

Some more options are listed here: How to format a JavaScript date - maybe you'll see something there. Based on a quick glance of the answers, what you're doing looks pretty good actually.

这篇关于Atom 编辑器:插入时间戳的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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