UnsupportedTemporalTypeException when formatting Instant to String

Time Zone To format an Instant a time-zone is required. Without a time-zone, the formatter does not know how to convert the instant to human date-time fields, and therefore throws an exception. The time-zone can be added directly to the formatter using withZone(). DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.SHORT ) .withLocale( Locale.UK ) .withZone( ZoneId.systemDefault() ); … Read more

Convert DataFrame column type from string to datetime

The easiest way is to use to_datetime: df[‘col’] = pd.to_datetime(df[‘col’]) It also offers a dayfirst argument for European times (but beware this isn’t strict). Here it is in action: In [11]: pd.to_datetime(pd.Series([’05/23/2005′])) Out[11]: 0 2005-05-23 00:00:00 dtype: datetime64[ns] You can pass a specific format: In [12]: pd.to_datetime(pd.Series([’05/23/2005′]), format=”%m/%d/%Y”) Out[12]: 0 2005-05-23 dtype: datetime64[ns]

Python datetime to string without microsecond component

If you want to format a datetime object in a specific format that is different from the standard format, it’s best to explicitly specify that format: >>> import datetime >>> datetime.datetime.now().strftime(“%Y-%m-%d %H:%M:%S”) ‘2011-11-03 18:21:26’ See the documentation of datetime.strftime() for an explanation of the % directives. Starting from Python 3.6, the isoformat() method is flexible … Read more

Format JavaScript date as yyyy-mm-dd

Just leverage the built-in toISOString method that brings your date to the ISO 8601 format: let yourDate = new Date() yourDate.toISOString().split(‘T’)[0] Where yourDate is your date object. Edit: @exbuddha wrote this to handle time zone in the comments: const offset = yourDate.getTimezoneOffset() yourDate = new Date(yourDate.getTime() – (offset*60*1000)) return yourDate.toISOString().split(‘T’)[0]

Given a DateTime object, how do I get an ISO 8601 date in string format?

Note to readers: Several commenters have pointed out some problems in this answer (related particularly to the first suggestion). Refer to the comments section for more information. DateTime.UtcNow.ToString(“yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz”, CultureInfo.InvariantCulture); Using custom date-time formatting, this gives you a date similar to 2008-09-22T13:57:31.2311892-04:00. Another way is: DateTime.UtcNow.ToString(“o”, CultureInfo.InvariantCulture); which uses the standard “round-trip” style (ISO 8601) to … Read more

Where can I find documentation on formatting a date in JavaScript?

I love 10 ways to format time and date using JavaScript and Working with Dates. Basically, you have three methods and you have to combine the strings for yourself: getDate() // Returns the date getMonth() // Returns the month getFullYear() // Returns the year Example: var d = new Date(); var curr_date = d.getDate(); var … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)