dateformatter

Define a few specific date formatters as members of an enum in Java

情到浓时终转凉″ 提交于 2019-12-08 06:49:27
问题 I need to track a few formats (DateTimeFormatter objects) for repeated use in my app. ➥ How to represent these formatter objects by using a Java enum? 回答1: tl;dr Yes. FormatDateOnly.DD_MM_YYYY.getFormatter() Details Yes, you can easily store some DateTimeFormatter objects in an enum. The slick enum facility in Java is quite powerful and flexible. Basically, an enum in Java is almost a normal Java class. Your enum can have member variables to store objects internally. Your enum can have a

Swift Date Timezone Issue

杀马特。学长 韩版系。学妹 提交于 2019-12-07 17:18:51
问题 extension Formatter { static let iso8601: DateFormatter = { let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) formatter.timeZone = TimeZone.init(identifier: "America/New_York") formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" return formatter }() } extension Date { var iso8601: String { return Formatter.iso8601.string(from: self) } } extension String { var dateFromISO8601: Date? { return Formatter.iso8601.date(from: self) // "Mar 22, 2017, 10:22 AM" } }

Swift Date Timezone Issue

会有一股神秘感。 提交于 2019-12-05 21:07:37
extension Formatter { static let iso8601: DateFormatter = { let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) formatter.timeZone = TimeZone.init(identifier: "America/New_York") formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" return formatter }() } extension Date { var iso8601: String { return Formatter.iso8601.string(from: self) } } extension String { var dateFromISO8601: Date? { return Formatter.iso8601.date(from: self) // "Mar 22, 2017, 10:22 AM" } } let dateFormat:String = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" let strDate: String = "2017-10-09T00:00:00.966Z"

Getting Wrong Date from dateFormat

家住魔仙堡 提交于 2019-12-02 20:27:58
问题 For date Input "00/02/02" formating Style is yy/MM/dd I am getting correct output like 02/01/2000 But issue is when trying with "00/01/01" getting output like this '01/01/12100' But I don't know why this year coming like 12100 My code is let str = "00/01/01" let inputFormatter = DateFormatter() inputFormatter.dateFormat = "yy/MM/dd" if let showDate = inputFormatter.date(from: str) { inputFormatter.dateFormat = "dd/MM/yyyy" let resultString = inputFormatter.string(from: showDate) print

Getting Wrong Date from dateFormat

我们两清 提交于 2019-12-02 08:33:17
For date Input "00/02/02" formating Style is yy/MM/dd I am getting correct output like 02/01/2000 But issue is when trying with "00/01/01" getting output like this '01/01/12100' But I don't know why this year coming like 12100 My code is let str = "00/01/01" let inputFormatter = DateFormatter() inputFormatter.dateFormat = "yy/MM/dd" if let showDate = inputFormatter.date(from: str) { inputFormatter.dateFormat = "dd/MM/yyyy" let resultString = inputFormatter.string(from: showDate) print(resultString) } year input type always as yy format. As per the @MartinR suggestion setting inputFormatter

i can select time at date picker when i get value from that in UTC so how to convert UTC time to GMT+05:30 to date?

我只是一个虾纸丫 提交于 2019-11-30 06:11:44
问题 var timeReminder = Date() let dateFormReminder = DateFormatter() dateFormReminder.calendar = Calendar.current dateFormReminder.dateFormat = "HH:mm a" dateFormReminder.timeZone = TimeZone(abbreviation: "GMT +05:30") timeReminder = dateFormReminder.date(from: txt_time.text!)! Image of date picker i am not get local time when i am convert time string to date value. OUTPUT:- 2000-01-01 07:12:00 +0000 回答1: You need to do like this UIDatePicker display Local DateTime but it returns UTC DateTime. So

DateFormatter returns unexpected date for Timezone

三世轮回 提交于 2019-11-29 16:25:21
I've read multiple posts about this, and most were due to not setting a specific Timezone and the system getting the current one. My scenario is slightly different and gives unexpected results, so I'll try to explain in detail. I'm dealing with a backend that returns dates split into a date and a time, stored as an Integer value. For example, a return value could be 131006 , which would translate to 13:10:06 . I know that this backend always returns the date in UTC . I cast this to a String and I convert the String to a Date with the following code: let timeFormatter = DateFormatter()

Show dates on seaborn heatmap

我的梦境 提交于 2019-11-28 13:11:24
I am trying to create a heat map from pandas dataframe using seaborn library. Here, is the code: test_df = pd.DataFrame(np.random.randn(367, 5), index = pd.DatetimeIndex(start='01-01-2000', end='01-01-2001', freq='1D')) ax = sns.heatmap(test_df.T) ax.xaxis.set_major_locator(mdates.MonthLocator()) ax.xaxis.set_minor_locator(mdates.DayLocator()) ax.xaxis.set_major_formatter(mdates.DateFormatter('%b')) ax.xaxis.set_minor_formatter(mdates.DateFormatter('%d')) However, I am getting a figure with nothing printed on the x-axis. Seaborn heatmap is a categorical plot. It scales from 0 to number of

What is the correct date.format for MMM dd, yyyy hh:mm:ss a? and how convert to dd-mm-yyyy HH:ii

回眸只為那壹抹淺笑 提交于 2019-11-26 23:47:13
问题 I want convert this: Dec 31, 2017 8:00:00 PM to dd-mm-yyyy HH:ii format in Swift 4. This is my code so far: let dateFormatter = DateFormatter() dateFormatter.dateFormat = "MMM dd, yyyy hh:mm:ss a"//this your string date format if let translatedDate = dateFormatter.date(from: datetime) { dateFormatter.dateFormat = "dd-MM-yyyy HH:ii" return dateFormatter.string(from: translatedDate) } The code never enters in the if statement. I guess my date format is not correct. 回答1: A DateFormatter that

How do I get the current Date in short format in Swift

和自甴很熟 提交于 2019-11-26 11:21:56
In the images below you can see the code I wrote and the values of all the variables: class fun getCurrentShortDate() -> String { var todaysDate = NSDate() var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy" var DateInFormat = dateFormatter.stringFromDate(todaysDate) return DateInFormat } Variable values As you can see the current date is found no problem, but when I try to change the NSDate to a string, it just won't do it. Xcode 8 or later • Swift 3 or later extension Date { func localizedDescription(dateStyle: DateFormatter.Style = .medium, timeStyle: DateFormatter