Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Bernard
23,262 PointsHaving Trouble with Build a Weather App in Swift - Part 2 Data Modeling With Structures
I am having a little trouble following along with what this question is asking... http://teamtreehouse.com/library/build-a-weather-app-with-swift/data-modeling-with-structures/customizing-dates
import Foundation
let secondsSinceBirth = NSTimeInterval(1200000000)
var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth)
var dateFormatter = NSDateFormatter()
Here is where I am starting. Thanks
5 Answers
zachkeith
10,719 PointsYou need to set the dateFormatter time and date styles that you can set the string.
Something like:
dateFormatter.timeStyle = .Short
dateFormatter.DateStyle = .Medium
Now you can set the string:
var stringDate = dateFormatter.stringFromDate(dateOfBirth)
yes thanks Marquay. Edited that now
Andrew Bernard
23,262 PointsThanks that helped a ton!
Had a few little changes but that was the general form. Thanks
Tomas Peciulis
16,450 PointsWhat's wrong with my code??
import Foundation
let secondsSinceBirth = NSTimeInterval(1200000000)
var dateOfBirth = NSDate(timeIntervalSince1970: secondsSinceBirth)
var dateFormatter = NSDateFormatter()
dateFormatter.timeStyle =.Short dateFormatter.DateStyle =.Medium
var stringDate = dateFormatter.stringFormDate(dateOfBirth)
Eric Whittaker
2,974 PointsWatch around 6:00 in the "Cleaning Up Our Date" video to find the problem with your syntax
Sergio Cisneros
13,078 PointsMy Code looks pretty much just like yours. Ive been trying different things and can't get it. Were you able to figure this out?
Andrew Bernard
23,262 PointsLook at your .Short and .Medium and see if that is the correct .notation for those Styles.
thomas howard
17,572 PointsThanks for all your insight. I'm sorry to say I was entirely confused, until I realized that I had spelled 'style' as 'sytle'. darn it.
Marquay Smith
7,865 PointsMarquay Smith
7,865 PointsProbably a typo but it should be: var stringDate = dateFormatter*.stringFromDate*(dateOfBirth)