Convert String Date in yyyy-MM-dd into Java UtilDatein format yyyy-MM-dd [duplicate]
This question already has an answer here:
want current date and time in “dd/MM/yyyy HH:mm:ss.SS” format
7 answers
return date type with format in java [duplicate]
1 answer
I want to take a date value as String in the format yyyy-MM-dd and return a jabva util date in the same format.
for this I am using below code , but the result is coming as "Wed Sep 18 00:00:00 CEST 2013"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
System.out.println(utilDate);
Do i need to consider the locale also ?
Please help to achieve this.
Thanks in advance
java simpledateformat
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 17:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 2 more comments
This question already has an answer here:
want current date and time in “dd/MM/yyyy HH:mm:ss.SS” format
7 answers
return date type with format in java [duplicate]
1 answer
I want to take a date value as String in the format yyyy-MM-dd and return a jabva util date in the same format.
for this I am using below code , but the result is coming as "Wed Sep 18 00:00:00 CEST 2013"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
System.out.println(utilDate);
Do i need to consider the locale also ?
Please help to achieve this.
Thanks in advance
java simpledateformat
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 17:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
The result ofsdf.parse(strdate)is just a string; assigning it toutilDateparses the string into a newDateobject. At no point is the formatting information transferred.
– MTCoster
Nov 14 '18 at 17:09
1
Simply doSystem.out.println(sdf.format(utilDate));
– Thomas Fritsch
Nov 14 '18 at 17:17
2
You might want to consider switching to LocalDate and DateFormatter classes from Java 8. It is the way to go. SimpleDateFormat is outdated
– SamwellTarly
Nov 14 '18 at 17:26
1
I recommend you avoid theSimpleDateFormatclass. It is not only long outdated, it is also notoriously troublesome. Today we have so much better injava.time, the modern Java date and time API.
– Ole V.V.
Nov 14 '18 at 17:47
2
@GauravRai1512 That standard ISO 8601 format is used by default in theLocalDateclass. No need to define a formatting pattern, no need to useDateTimeFormatter. Just use:LocalDate.parse( "2018-01-23" )
– Basil Bourque
Nov 14 '18 at 20:30
|
show 2 more comments
This question already has an answer here:
want current date and time in “dd/MM/yyyy HH:mm:ss.SS” format
7 answers
return date type with format in java [duplicate]
1 answer
I want to take a date value as String in the format yyyy-MM-dd and return a jabva util date in the same format.
for this I am using below code , but the result is coming as "Wed Sep 18 00:00:00 CEST 2013"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
System.out.println(utilDate);
Do i need to consider the locale also ?
Please help to achieve this.
Thanks in advance
java simpledateformat
This question already has an answer here:
want current date and time in “dd/MM/yyyy HH:mm:ss.SS” format
7 answers
return date type with format in java [duplicate]
1 answer
I want to take a date value as String in the format yyyy-MM-dd and return a jabva util date in the same format.
for this I am using below code , but the result is coming as "Wed Sep 18 00:00:00 CEST 2013"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
System.out.println(utilDate);
Do i need to consider the locale also ?
Please help to achieve this.
Thanks in advance
This question already has an answer here:
want current date and time in “dd/MM/yyyy HH:mm:ss.SS” format
7 answers
return date type with format in java [duplicate]
1 answer
java simpledateformat
java simpledateformat
asked Nov 14 '18 at 17:05
SambuddhaSambuddha
13014
13014
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 17:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 17:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
The result ofsdf.parse(strdate)is just a string; assigning it toutilDateparses the string into a newDateobject. At no point is the formatting information transferred.
– MTCoster
Nov 14 '18 at 17:09
1
Simply doSystem.out.println(sdf.format(utilDate));
– Thomas Fritsch
Nov 14 '18 at 17:17
2
You might want to consider switching to LocalDate and DateFormatter classes from Java 8. It is the way to go. SimpleDateFormat is outdated
– SamwellTarly
Nov 14 '18 at 17:26
1
I recommend you avoid theSimpleDateFormatclass. It is not only long outdated, it is also notoriously troublesome. Today we have so much better injava.time, the modern Java date and time API.
– Ole V.V.
Nov 14 '18 at 17:47
2
@GauravRai1512 That standard ISO 8601 format is used by default in theLocalDateclass. No need to define a formatting pattern, no need to useDateTimeFormatter. Just use:LocalDate.parse( "2018-01-23" )
– Basil Bourque
Nov 14 '18 at 20:30
|
show 2 more comments
1
The result ofsdf.parse(strdate)is just a string; assigning it toutilDateparses the string into a newDateobject. At no point is the formatting information transferred.
– MTCoster
Nov 14 '18 at 17:09
1
Simply doSystem.out.println(sdf.format(utilDate));
– Thomas Fritsch
Nov 14 '18 at 17:17
2
You might want to consider switching to LocalDate and DateFormatter classes from Java 8. It is the way to go. SimpleDateFormat is outdated
– SamwellTarly
Nov 14 '18 at 17:26
1
I recommend you avoid theSimpleDateFormatclass. It is not only long outdated, it is also notoriously troublesome. Today we have so much better injava.time, the modern Java date and time API.
– Ole V.V.
Nov 14 '18 at 17:47
2
@GauravRai1512 That standard ISO 8601 format is used by default in theLocalDateclass. No need to define a formatting pattern, no need to useDateTimeFormatter. Just use:LocalDate.parse( "2018-01-23" )
– Basil Bourque
Nov 14 '18 at 20:30
1
1
The result of
sdf.parse(strdate) is just a string; assigning it to utilDate parses the string into a new Date object. At no point is the formatting information transferred.– MTCoster
Nov 14 '18 at 17:09
The result of
sdf.parse(strdate) is just a string; assigning it to utilDate parses the string into a new Date object. At no point is the formatting information transferred.– MTCoster
Nov 14 '18 at 17:09
1
1
Simply do
System.out.println(sdf.format(utilDate));– Thomas Fritsch
Nov 14 '18 at 17:17
Simply do
System.out.println(sdf.format(utilDate));– Thomas Fritsch
Nov 14 '18 at 17:17
2
2
You might want to consider switching to LocalDate and DateFormatter classes from Java 8. It is the way to go. SimpleDateFormat is outdated
– SamwellTarly
Nov 14 '18 at 17:26
You might want to consider switching to LocalDate and DateFormatter classes from Java 8. It is the way to go. SimpleDateFormat is outdated
– SamwellTarly
Nov 14 '18 at 17:26
1
1
I recommend you avoid the
SimpleDateFormat class. It is not only long outdated, it is also notoriously troublesome. Today we have so much better in java.time, the modern Java date and time API.– Ole V.V.
Nov 14 '18 at 17:47
I recommend you avoid the
SimpleDateFormat class. It is not only long outdated, it is also notoriously troublesome. Today we have so much better in java.time, the modern Java date and time API.– Ole V.V.
Nov 14 '18 at 17:47
2
2
@GauravRai1512 That standard ISO 8601 format is used by default in the
LocalDate class. No need to define a formatting pattern, no need to use DateTimeFormatter. Just use: LocalDate.parse( "2018-01-23" )– Basil Bourque
Nov 14 '18 at 20:30
@GauravRai1512 That standard ISO 8601 format is used by default in the
LocalDate class. No need to define a formatting pattern, no need to use DateTimeFormatter. Just use: LocalDate.parse( "2018-01-23" )– Basil Bourque
Nov 14 '18 at 20:30
|
show 2 more comments
1 Answer
1
active
oldest
votes
Please try below code.
You also have to format your simpleDateFormat object and pass utilDate object inside it to create formatted date as specified by you.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest
public static void main(String args) throws ParseException
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
String date=sdf.format(utilDate );
System.out.println(date);
We can also implement through Java8 like below:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateTest
public static void main(String args) throws ParseException
String strdate = "2013-09-18";
DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(strdate, formatter);
System.out.println(date.format(formatter));
or you can also use only LocalDate to change in java util like below.
import java.time.LocalDate;
public class TestCircle
public static void main(String args)
String strdate = "2013-09-18";
LocalDate date = LocalDate.parse(strdate);
System.out.println(date);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please try below code.
You also have to format your simpleDateFormat object and pass utilDate object inside it to create formatted date as specified by you.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest
public static void main(String args) throws ParseException
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
String date=sdf.format(utilDate );
System.out.println(date);
We can also implement through Java8 like below:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateTest
public static void main(String args) throws ParseException
String strdate = "2013-09-18";
DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(strdate, formatter);
System.out.println(date.format(formatter));
or you can also use only LocalDate to change in java util like below.
import java.time.LocalDate;
public class TestCircle
public static void main(String args)
String strdate = "2013-09-18";
LocalDate date = LocalDate.parse(strdate);
System.out.println(date);
add a comment |
Please try below code.
You also have to format your simpleDateFormat object and pass utilDate object inside it to create formatted date as specified by you.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest
public static void main(String args) throws ParseException
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
String date=sdf.format(utilDate );
System.out.println(date);
We can also implement through Java8 like below:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateTest
public static void main(String args) throws ParseException
String strdate = "2013-09-18";
DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(strdate, formatter);
System.out.println(date.format(formatter));
or you can also use only LocalDate to change in java util like below.
import java.time.LocalDate;
public class TestCircle
public static void main(String args)
String strdate = "2013-09-18";
LocalDate date = LocalDate.parse(strdate);
System.out.println(date);
add a comment |
Please try below code.
You also have to format your simpleDateFormat object and pass utilDate object inside it to create formatted date as specified by you.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest
public static void main(String args) throws ParseException
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
String date=sdf.format(utilDate );
System.out.println(date);
We can also implement through Java8 like below:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateTest
public static void main(String args) throws ParseException
String strdate = "2013-09-18";
DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(strdate, formatter);
System.out.println(date.format(formatter));
or you can also use only LocalDate to change in java util like below.
import java.time.LocalDate;
public class TestCircle
public static void main(String args)
String strdate = "2013-09-18";
LocalDate date = LocalDate.parse(strdate);
System.out.println(date);
Please try below code.
You also have to format your simpleDateFormat object and pass utilDate object inside it to create formatted date as specified by you.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest
public static void main(String args) throws ParseException
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strdate = "2013-09-18";
Date utilDate = sdf.parse(strdate);
String date=sdf.format(utilDate );
System.out.println(date);
We can also implement through Java8 like below:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateTest
public static void main(String args) throws ParseException
String strdate = "2013-09-18";
DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(strdate, formatter);
System.out.println(date.format(formatter));
or you can also use only LocalDate to change in java util like below.
import java.time.LocalDate;
public class TestCircle
public static void main(String args)
String strdate = "2013-09-18";
LocalDate date = LocalDate.parse(strdate);
System.out.println(date);
edited Nov 15 '18 at 3:28
answered Nov 14 '18 at 17:51
GauravRai1512GauravRai1512
58811
58811
add a comment |
add a comment |
1
The result of
sdf.parse(strdate)is just a string; assigning it toutilDateparses the string into a newDateobject. At no point is the formatting information transferred.– MTCoster
Nov 14 '18 at 17:09
1
Simply do
System.out.println(sdf.format(utilDate));– Thomas Fritsch
Nov 14 '18 at 17:17
2
You might want to consider switching to LocalDate and DateFormatter classes from Java 8. It is the way to go. SimpleDateFormat is outdated
– SamwellTarly
Nov 14 '18 at 17:26
1
I recommend you avoid the
SimpleDateFormatclass. It is not only long outdated, it is also notoriously troublesome. Today we have so much better injava.time, the modern Java date and time API.– Ole V.V.
Nov 14 '18 at 17:47
2
@GauravRai1512 That standard ISO 8601 format is used by default in the
LocalDateclass. No need to define a formatting pattern, no need to useDateTimeFormatter. Just use:LocalDate.parse( "2018-01-23" )– Basil Bourque
Nov 14 '18 at 20:30