[英]rails - get YYYY-MM-dd date format in string
I'm not sure why I can't figure this out it's so simple. 我不确定为什么我无法弄清楚它是如此简单。
I'm trying to concatenate todays date in the format YYYY-MM-dd to a string and it doesn't work. 我正在尝试将今天的日期以YYYY-MM-dd的格式连接到字符串,但是它不起作用。
I've tried creating the date with now = Time.now.strftime("%Y-%m-%d")
and concatenating it like this 我尝试用now = Time.now.strftime("%Y-%m-%d")
创建日期并将其连接起来
'http://api.flurry.com/appMetrics/Sessions?apiAccessCode=########&apiKey=#########&startDate='+now+'&endDate='+now
Please advise, thank you. 请指教,谢谢。
edit: If I set now = '2016-11-05'
then everything works fine. 编辑:如果我now = '2016-11-05'
设置now = '2016-11-05'
那么一切正常。 So the issue is definitely in how I'm creating my date. 因此,问题绝对在于我如何创建约会。
I ended up making it work with string interpolation after it not working with string interpolation. 在不使用字符串插值后,我最终使其与字符串插值一起工作。 Why wasn't it working? 为什么不起作用? Turns out you have to use double quotes if not it takes the interpolation as literal!! 事实证明,如果不使用双引号,则必须使用双引号!
now = Time.now.strftime("%Y-%m-%d")
"http://api.flurry.com/appMetrics/Sessions?apiAccessCode=########&apiKey=#########&startDate=#{now}&endDate=#{now}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.