---
title: "Java string to date conversion"  
description: "Java string to date conversion"  
author: "Mark Devid"  
published: 2015-08-10  
updated: 2015-08-10  
canonical: https://www.mindstick.com/forum/33406/java-string-to-date-conversion  
category: "java"  
tags: ["java", "datetime", "string"]  
reading_time: 1 minute  

---

# Java string to date conversion

Can somebody recommend the best way to convert a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) in the [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) 'January 2, 2010' to a date in [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)? Ultimately, I want to break out the month, the day, and the year as integers so that I can use:\

```
Date date = new Date();date.setMonth()..date.setYear()..date.setDay()..date.setlong currentTime = date.getTime();
```

to [convert the date](https://www.mindstick.com/forum/158272/how-to-convert-the-date-format-to-ut-in-json) into time.

## Replies

### Reply by Anonymous User

```
String string = "January 2, 2010";DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);Date date = format.parse(string);System.out.println(date); // Sat Jan 02 00:00:00 GMT 2010
```

\
If you happen to be on Java 8 already, then use DateTimeFormatter (also here, click the link to see all predefined formatters and available format patterns; the tutorial is available here). This new API is inspired by JodaTime.

```
String string = "January 2, 2010";DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH);LocalDate date = LocalDate.parse(string, formatter);System.out.println(date); // 2010-01-02
```


---

Original Source: https://www.mindstick.com/forum/33406/java-string-to-date-conversion

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
