获得本月第一天最有效的方法是什么? [英] What's the most efficient way get the first day of the current month?

查看:57
本文介绍了获得本月第一天最有效的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ruby尝试格式化日期,例如:2009-10-01

With ruby I'm trying to get format a date as such: 2009-10-01

我将当前日期取为哪里(2009-10-26)然后将日期更改为 01。

Where I take the current date (2009-10-26) and then change the day to "01".

我知道执行此操作的方法,但是很好奇,最短的方法是实现这一目标。

I know of ways to do this, but was curious what the shortest way is, code wise, to pull this off.

推荐答案

Time.parse("2009-10-26").strftime("%Y-%m-01")

这篇关于获得本月第一天最有效的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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