简体   繁体   English

rails-以字符串形式获取YYYY-MM-dd日期格式

[英]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.

相关问题 如何在rails上的ruby中将日期格式从dd-mmm-yyyy转换为yyyy-mm-dd - how to convert the date format from dd-mmm-yyyy to yyyy-mm-dd in ruby on rails Rails日期格式(匹配YYYY-MM-DD HH-MM-SS) - Rails Date Format (To match YYYY-MM-DD HH-MM-SS) Rails 3,MySQL Production只允许以mm / dd / yyyy或yyyy-mm-dd格式的日期输入dd / mm / yyyy - Rails 3, MySQL Production only allows dates in mm/dd/yyyy or yyyy-mm-dd format need to input in dd/mm/yyyy Ruby on Rails - 如何以我需要的格式显示日期? 从YYYY-MM-DD HH:MM:SS UTC转换为MM / DD / YYYY - Ruby on Rails - how to display a date in format i need? Converting from YYYY-MM-DD HH:MM:SS UTC to MM/DD/YYYY 正则表达式验证 YYYY-MM-DD 格式 - Regex validation YYYY-MM-DD format Rails转换yyyy-MM-dd'T'HH:mm:ssZ至今 - Rails Convert yyyy-MM-dd'T'HH:mm:ssZ To date 如何将日期格式从yyyy / mm / dd更改为dd / mm / yyyy Ruby on Rails - How to change date format from yyyy/mm/dd to dd/mm/yyyy Ruby on Rails 让轨道接受欧洲日期格式(年/月/日) - Getting rails to accept European date format (dd/mm/yyyy) 如何在Rails中以“mm / dd / yyyy”格式显示当前日期 - How to display the current date in “mm/dd/yyyy” format in Rails 如何将Rails%d /%m /%Y日期格式字符串转换为dd / mm / yyyy? - How to convert Rails %d/%m/%Y date format string to dd/mm/yyyy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM