In what format is this date string?
The proper format is yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ
.
See Unicode Date Format Patterns.
Also, the ZZZZZ
format for the +00:00
timezone format was added to iOS 6 and is not supported under iOS 5 or earlier.
What is this date format? 2011-08-12T20:17:46.384Z
The T is just a literal to separate the date from the time, and the Z means "zero hour offset" also known as "Zulu time" (UTC). If your strings always have a "Z" you can use:
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
Or using Joda Time, you can use ISODateTimeFormat.dateTime()
.
Convert string to date then format the date
Use SimpleDateFormat#format(Date):
String start_dt = "2011-01-01";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD");
Date date = (Date)formatter.parse(start_dt);
SimpleDateFormat newFormat = new SimpleDateFormat("MM-dd-yyyy");
String finalString = newFormat.format(date);
Format a date string in javascript
Use Moment.js and the .format
function.
moment('2017-06-10T16:08:00').format('MM/DD/YYYY');
Will output
06/10/2017
Beside the format
function Moment.js will enrich you will alot more useful functions.
C# DateTime to YYYYMMDDHHMMSS format
DateTime.Now.ToString("yyyyMMddHHmmss"); // case sensitive
Convert String Date to String date different format
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
Date date = format1.parse("2013-02-21");
System.out.println(format2.format(date));
Format JavaScript date as yyyy-mm-dd
You can do:
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
console.log(formatDate('Sun May 11,2014'));
How to format date string in java?
use SimpleDateFormat
to first parse()
String
to Date
and then format()
Date
to String
DateTime string format in c#
If I understand correctly, you can use DateTime.Today
property like;
var dt1 = DateTime.Today;
var dt2 = DateTime.Today.AddDays(1).AddSeconds(-1);
and use DateTime.ToString()
to format them like;
var DateFormatFrom = dt1.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
var FilloutDateTo = dt2.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
Results will be;
12/04/2014 00:00:00
12/04/2014 23:59:59
You used hh
format specifier but it is for 12-hour clock. Use HH
format specifier instead which is for 24-hour clock. And since your result strings doesn't have any AM/PM designator, you don't need to use tt
format specifier.
Related Topics
Determine The Maximum Number of Characters a UIlabel Can Take
How to Sort Core Data Array Based on Date Entered
Conversion from String to Date in Swift Returns Nil
Realm Crashes with Rlmexception: Object Has Been Deleted or Invalidated
Exceeding Max Text("") Concatenation Length - Swiftui -
How Come My Drawing Code Keeps Resulting in Fuzzy Shapes
View Height Problems (Continued)
Play Keyboard Click Sound in a Collection View Controller
How to Install Self-Signed Certificates in iOS 11
Uilabel Word Wrap Feature Leaving Space Even When Sufficient Space Available for The Word
Invalid Transaction Receipt Returned by Appstorereceipturl (Nsdata), in iOS 7
Ld: Library Not Found for -Ldoubleconversion React Native 0.59
Screenshot on Swift Programmatically
Passing Data Between View Controllers: from UItableview to a Details View Controller
Fixing Low Fps in Swift Playground
Xcode 8.3 Swift Version Error (Swift_Version) in Objective C Project