How can I parse/format dates with LocalDateTime? (Java 8)

Parsing date and time To create a LocalDateTime object from a string you can use the static LocalDateTime.parse() method. It takes a string and a DateTimeFormatter as parameter. The DateTimeFormatter is used to specify the date/time pattern. String str = “1986-04-08 12:30”; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm”); LocalDateTime dateTime = LocalDateTime.parse(str, formatter); Formatting date and … Read more

Specifying date format when converting with pandas.to_datetime

You can use the parse_dates option from read_csv to do the conversion directly while reading you data. The trick here is to use dayfirst=True to indicate your dates start with the day and not with the month. See here for more information: When your dates have to be the index: >>> import pandas as … Read more

Set timezone in PHP and MySQL

In PHP: <?php define(‘TIMEZONE’, ‘Europe/Paris’); date_default_timezone_set(TIMEZONE); For MySQL: <?php $now = new DateTime(); $mins = $now->getOffset() / 60; $sgn = ($mins < 0 ? -1 : 1); $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; $offset = sprintf(‘%+d:%02d’, $hrs*$sgn, $mins); //Your DB Connection – sample $db = new PDO(‘mysql:host=localhost;dbname=test’, ‘dbuser’, … Read more

Convert date from excel in number format to date format python [duplicate]

from datetime import datetime excel_date = 42139 dt = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + excel_date – 2) tt = dt.timetuple() print(dt) print(tt) As mentioned by J.F. Sebastian, this answer only works for any date after 1900/03/01 EDIT: (in answer to @R.K) If your excel_date is a float number, use this code: from datetime import datetime def … Read more

Parse Date String to Some Java Object

Using Joda-Time, take a look at DateTimeFormat; it allows parsing both kind of date strings that you mention (and almost any other arbitrary formats). If your needs are even more complex, try DateTimeFormatterBuilder. To parse #1: DateTimeFormatter f = DateTimeFormat.forPattern(“yyyy-MM-dd HH:mm:ss”); DateTime dateTime = f.parseDateTime(“2012-01-10 23:13:26”); Edit: actually LocalDateTime is a more appropriate type for … Read more