nscalendar - IOS Swift NSDate from String output GMT midnigth -


i want store in sqlite database timeintervalsince1970. if use code:

let dateformatter = nsdateformatter() dateformatter.dateformat = "dd-mm-yyyy hh:mm" dateformatter.timezone = nstimezone.localtimezone() var initdate: nsdate = dateformatter.datefromstring("23-03-2015 00:00")! let timeinseconds = initdate.timeintervalsince1970 // 1,427,324,400.0 

when pass timeinseconds nsdate:

let datestore: nsdate = nsdate(timeintervalsince1970: timeinseconds) 

if print datestore:

println(datestore) 

output '2015-03-22 23:00:00 +0000'

timeinseconds = 1427324400.0 -> '2015-03-22 23:00:00 +0000', store '2015-03-23 00:00:00 +0000' interval should 1427328000.0

i not know how it.

when use code:

let cal2: nscalendar = nscalendar.currentcalendar() cal2.timezone = nstimezone(name: "europe/madrid")!  var timezonecomps: nsdatecomponents = nsdatecomponents()  timezonecomps.day = 23 timezonecomps.month = 3 timezonecomps.year = 2015 timezonecomps.hour = 0 timezonecomps.minute = 0 timezonecomps.second = 0  var date1: nsdate = cal2.datefromcomponents(timezonecomps)! println(date1) 

output println: 2015-03-22 23:00:00 +0000

any help, please?

let dateformatter = nsdateformatter() dateformatter.dateformat = "dd-mm-yyyy hh:mm" let mydatemidnightlocaltime = dateformatter.datefromstring("23-03-2015 00:00")!  // mar 23, 2015, 12:00 let timeinseconds = mydatemidnightlocaltime.timeintervalsince1970                // 1,427,079,600.0   let datestored = nsdate(timeintervalsince1970: timeinseconds)                    // mar 23, 2015, 12:00  matches datestored.timeintervalsince1970                                                 // 1,427,079,600.0  matches   

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -