简体   繁体   中英

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.

I've tried creating the date with now = Time.now.strftime("%Y-%m-%d") and concatenating it like this

'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. 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}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM