DateTime.ToString() format that can be used in a filename or extension?
You can use this: DateTime.Now.ToString(“yyyy-dd-M–HH-mm-ss”);
You can use this: DateTime.Now.ToString(“yyyy-dd-M–HH-mm-ss”);
When the number being returned by your formula is being formatted as a time, and you want it formatted as a plain number, change the format of the cell to a plain number format: click the cell and then click Format, Number, Normal. Time values in Google spreadsheet are represented as days and parts of … Read more
It turns out Java does not accept a bare Date value as DateTime. Using LocalDate instead of LocalDateTime solves the issue: DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyyMMdd”); LocalDate dt = LocalDate.parse(“20140218”, formatter);
How about: dateTime.ToString(“tt”, CultureInfo.InvariantCulture);
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
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]
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
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]
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
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