cost 159 ms
將 Swift 日期從一個時區調整到另一個時區未產生預期結果

[英]Adjusting Swift Date from one timezone to another is not producing expected result

我真的在為日期和時區而苦苦掙扎。 我的理解是Date與時區無關,只是一個時間點。 我正在編寫一個單元測試,我想創建一個Date object,如果用戶所在的時區與我正在運行測試的默認倫敦區不同,那么它代表現在的時間,然后將其轉換為不同的時區。 我首先使用帶有預計時間的DateComponents創建 ...

從 SwiftUI 中的核心數據中獲取特定年份數據的謂詞

[英]Predicate for fetching the data for a particular year from Core Data in SwiftUI

我正在開發一個 SwiftUI 預算管理應用程序,用於跟蹤用戶的支出和收入。 該應用程序使用 CoreData 來管理數據管理。 托管 object 的日期是一個財產。 我使用下面的獲取請求來獲取數據 這將提供分組數據,例如 2021 年 9 月的費用管理的object model如下 我想根據年份 ...

如何為當前語言環境生成 DateComponents.weekday 值的有序列表

[英]How to generate an ordered list of DateComponents.weekday values for the current locale

來自DateComponents.weekday的文檔工作日單位是從 1 到 n 的數字,其中 n 是一周中的天數。 例如,在公歷中,n 為 7,星期日用 1 表示。 從Calendar.firstWeekday firstWeekday 的默認值因日歷和區域設置而異...對於公歷和 ISO 86 ...

dateComponents() from... to in days 從現在到明天顯示為 0 天?

[英]dateComponents() from... to in days shows from now to tomorrow as 0 days?

我有代表未來某個時間的 datecomponent 對象。 我想計算從現在到那個日期有多少個日期。 我還簡單地將日期表示為日期。 我發現,當我試圖顯示“明天”的日期有多少時,它顯示為 0。在我看來,它應該顯示為 1。我可以嘗試一種 hacky 方法,將 1 添加到我的計數,但我想知道是因為它試圖四 ...

如何將 NSDateComponents 轉換為字符串?

[英]How to Convert NSDateComponents to String?

<NSDateComponents: 0x282884930> { 日歷年: 2022 月: 7 天: 12 小時: 12 分鍾: 23 如何將其轉換為更易讀的格式:“2022 年 7 月 12 日,上午 12:23”? ...

如何使用新的 Foundation 格式化方法格式化時間間隔?

[英]How to format a time interval with the new Foundation formatted method?

我正在嘗試將DateComponentsFormatter與新的 Foundation 格式化程序一起使用。 要格式化日期,我可以這樣做: 但是,我正在嘗試使用這個新 API 來使用DateComponentsFormatter : 如何使用DateComponentsFormatter的新 ...

如何將 DateComponent 'day' 轉換為 Int 以獲取以天為單位的持續時間數組的平均值,或者如何獲取 DateComponents 的平均值?

[英]How to convert DateComponent 'day' to Int for getting average of Array of durations in days, or way to get an avg of DateComponents?

我有一個 DateComponents 數組,每個都像這樣生成: Calendar.current.dateComponents([.day], from: lastPeriodStart!, to: Date()) 打印時的示例是: day: -3 isLeapMonth: false 基本上 ...

在 Swift 中將月份值添加到日期的問題

[英]Problem with adding month value to date in Swift

我有問題。 我正在獲取當前年份的開始日期,功能如下: 我的目標是遍歷這個日期以提取每個月的數據。 我使用此函數將值添加到 .month 以獲取一年中每個月的開始日期: 當我遍歷此功能並打印日期時,我收到以下信息: 輸出: 如您所見,從 2022-03-31 開始存在問題 - 它應該返 ...

iOS diff in days using dateComponent(_:from:to:) - nil 對結果日意味着什么?

[英]iOS diff in days using dateComponent(_:from:to:) - what does nil mean for the result day?

我正在計算兩個Date之間的差異: let diff = Calendar.current.dateComponents([.day], from: oldDate, to newDate) 結果我得到了一個DateComponents ,其中day屬性是可選的,文檔並沒有說在這個計算中保證有一 ...

DateComponents 似乎不尊重年份

[英]DateComponents doesn't seem to honor year

我正在嘗試將Date轉換為DateComponents ,更改一些屬性,並獲取新的Date 。 我編寫了以下代碼: 我已經在 iOS 15.0 上的 iOS 模擬器以及運行最新 macOS Big Sur 和 Xcode 13.0 的 Mac 上的 Swift REPL 上在America/De ...

dateComponents(_, from, to) 返回錯誤數據,直到 Picker 被觸摸

[英]dateComponents(_, from, to) returning wrong data until Picker touched

我有 2 個 DatePickers,用戶可以在其中 select 小時和分鍾。 一旦選擇器被更改, “calcDuration”函數就會被調用,該函數應該計算時間差,並以小時和分鍾的形式將其顯示在 label 上。 基本 storyboard 設置 如果我運行應用程序並將較低 datePicker ...

每 n 天安排一次本地通知(時區安全)

[英]Schedule local notification every n days (timezone safe)

我相信這個問題已經被問過好幾次了,但沒有一個明確的答案。 有兩種安排時間通知的方法: UNCalendarNotification和UNTimeIntervalNotificationTrigger 。 在一周中的特定時間和日期安排通知是微不足道的,與在一個月的特定日期相同,但在特定時間安排通知, ...

帶有 FetchedResultsController 的 titleForHeaderInSection 的日期

[英]Date for titleForHeaderInSection with FetchedResultsController

我有一個屬性@NSManaged public var sectionKeyDate: Date? 我正在嘗試使用sectionKey 。 我在從NSFetchedResultsSectionInfo獲取結果字符串以格式化為Date ,然后再轉換回格式化字符串時遇到問題。 從字符串到日期的轉換失敗並 ...

Swift 以納秒為單位的日期差異不起作用

[英]Swift date difference in nanoseconds is not working

我正在實現一個計時器,該計時器需要計算用戶處於非活動狀態的毫秒數並計算差異並恢復計時器。 由於 dateComponents 中沒有毫秒選項,因此我使用了納秒,但是,當我嘗試計算兩個日期之間的納秒間隔時,每次都會得到相同的結果(當前日期正在改變,應該得到不同的結果),如果我改變納秒到秒,它的工作原理 ...

將小時和分鍾整數格式化為字符串“9:30 am”

[英]Format hour and minute integers as the String “9:30 am”

如何將小時和分鍾 integer 值表示為格式為“9:30 am”的字符串? 目前,我有: 我知道我可以在最后手動連接時間子午線,但我希望有一個內置的 function 用於此。 也許是不同的UnitsStyle ? ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM