Problem got resolved after I followed @Basil Bourque's suggestion and specified the correct locale to the DateTimeFormatter.