date

Swift: Compare date by days

主宰稳场 提交于 2020-05-10 14:02:20
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Swift: Compare date by days

纵饮孤独 提交于 2020-05-10 14:01:14
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Swift: Compare date by days

假如想象 提交于 2020-05-10 13:55:24
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Chart.js creating a line graph using dates

て烟熏妆下的殇ゞ 提交于 2020-05-10 07:43:16
问题 I can't seem to get Chart.js to work with dates. I have tried quite a few different methods: let examChart = document.getElementById("examChart").getContext("2d"); let examLineChart = new Chart(examChart, { type: "line", data: [ { t: new Date("2015-3-15 13:3"), y: 12 }, { t: new Date("2015-3-25 13:2"), y: 21 }, { t: new Date("2015-4-25 14:12"), y: 32 } ], options: { label: "placeholder" } }); And: let examChart = document.getElementById("examChart").getContext("2d"); let examLineChart = new

Comparing only dates of DateTimes in Dart

纵然是瞬间 提交于 2020-05-10 07:33:00
问题 I need to store and compare dates (without times) in my app, without caring about time zones. I can see three solutions to this: (date1.year == date2.year && date1.month == date2.month && date1.day == date2.day) This is what I'm doing now, but it's horrible verbose. date1.format("YYYYMMDD") == date2.format("YYYYMMDD") This is still rather verbose (though not as bad), but just seems inefficient to me... Create a new Date class myself, perhaps storing the date as a "YYYYMMDD" string, or number

Comparing only dates of DateTimes in Dart

让人想犯罪 __ 提交于 2020-05-10 07:32:07
问题 I need to store and compare dates (without times) in my app, without caring about time zones. I can see three solutions to this: (date1.year == date2.year && date1.month == date2.month && date1.day == date2.day) This is what I'm doing now, but it's horrible verbose. date1.format("YYYYMMDD") == date2.format("YYYYMMDD") This is still rather verbose (though not as bad), but just seems inefficient to me... Create a new Date class myself, perhaps storing the date as a "YYYYMMDD" string, or number

Convert from UTC to local timezone give wrong result

烂漫一生 提交于 2020-05-09 11:55:22
问题 Background I need to convert time string with format: "HH:mm" from UTC to local timezone. For example if UTC time is 09:00, local time (Stockholm/Europe) should be two hours ahead. Problem When I convert 09:00 (UTC) to Stockholm/Europe time I get 10:00. It should be 11:00. func UTCToLocal(date:String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm" dateFormatter.timeZone = TimeZone(abbreviation: "UTC") let dt = dateFormatter.date(from: date) dateFormatter

Convert from UTC to local timezone give wrong result

别等时光非礼了梦想. 提交于 2020-05-09 11:55:10
问题 Background I need to convert time string with format: "HH:mm" from UTC to local timezone. For example if UTC time is 09:00, local time (Stockholm/Europe) should be two hours ahead. Problem When I convert 09:00 (UTC) to Stockholm/Europe time I get 10:00. It should be 11:00. func UTCToLocal(date:String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm" dateFormatter.timeZone = TimeZone(abbreviation: "UTC") let dt = dateFormatter.date(from: date) dateFormatter

date-fns returns invalid date on safari

喜你入骨 提交于 2020-05-09 10:38:20
问题 I'm using date-fns to return some values as shown below: import { format, formatDistance } from "date-fns"; var date = new Date("2019-03-06 00:00:00"); console.log(format(new Date(date), "dd MMM, y")); It works fine on Chrome and returns We Mar, y But returns Invalid Date in Safari. I believe it's because the date ("2019-03-06 00:00:00") is not in ISO 8601 format. But this is the format I'm receiving from an endpoint. Is there any option to convert this to the right format and make it work on

Creating a function that returns a date in Google Sheets

独自空忆成欢 提交于 2020-05-09 06:24:05
问题 I created a function that takes in a date and number of months to add to that date and returns the next date. The function seems to be working perfectly, which I check using DEBUG. The strange thing is when I logger in the returned date using the line below, monthstoadd = 18 date1.setFullYear(2019, 6, 1); returnDate = AddMonths(date1, monthstoadd); // my selfmade function Logger.log("returnDate(1):", returnDate.getMonth(), "/" , returnDate.getDay(), "/", returnDate.getFullYear()); the date in