This question already has answers here:
How do I convert a date/time string to a DateTime object in Dart?
(8 answers)
Closed 2 years ago.
I am getting date in String and I want to convert it into given Date format. Can anyone please guide me how can I do it ?
String myDate = 'June-2020'
I am getting date like this and I want to convert it into this 2020-06-01 format. 01 is default for every month.
var convertedDate = '2020-06-01'
You can create custom date format using intl package
String dateString1 = 'June-2020';
String dateString2 = 'May-2021';
DateFormat dateFormate = DateFormat('MMMM-yyyy');
DateTime date1 = dateFormate.parse(dateString1);
DateTime date2 = dateFormate.parse(dateString2);
print(date1); //2020-06-01 00:00:00.000
print(date2); //2020-05-01 00:00:00.000
Related
This question already has answers here:
How to Convert UNIX epoch time to Date and time in ios swift
(3 answers)
Closed 1 year ago.
There's a value representing Unix Epoch timestamp in milliseconds as a String:
let val = "1492495200000"
How to transform this value to Date in swift?
Please try this one :
let val = 1492495200000;
var date = Date(timeIntervalSince1970: (Double(val) / 1000.0));
print(date);
Well your value is time interval in milliseconds. This is reason why you should do division by 1000, before you will do date convert.
This question already has answers here:
How do I convert a date/time string to a DateTime object in Dart?
(8 answers)
Closed 1 year ago.
I am trying to format my date and time.
My code
String dateStart = data[i]['notification_date'];
DateTime input = DateTime.parse(dateStart);
String datee = DateFormat('hh:mm a').format(input);
its showing error Unhandled Exception: FormatException: Invalid date format
right now its look like this 22-04-2021 05:57:58 PM
You have an issue in following line:
DateTime input = DateTime.parse(dateStart);
Thing is that default parse method does not support '22-04-2021 05:57:58 PM' format, as it is not standard. You should specify its format to parse like this:
String dateStart = '22-04-2021 05:57:58 PM';
DateFormat inputFormat = DateFormat('dd-MM-yyyy hh:mm:ss a');
DateTime input = inputFormat.parse(dateStart);
String datee = DateFormat('hh:mm a').format(input);
I need to convert the date string of type WEEKDAY DATE MONTHNAME, Example: from "Monday 5 October" to date object.
I have tried with
Utilities.formatDate(new Date("Monday 5 October"), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'")
How do I convert it, I am ok using V8 apps script engine
The Date constructor accepts timestamp strings formatted according to IETF-compliant RFC 2822 timestamps and ISO8601.
There are many ways to convert your string to date, but probably one of the simplest is appending the current year to your string, using getFullYear():
const source = "Monday 5 October";
const date = new Date(`${source} ${new Date().getFullYear()}`);
Reference:
Date() constructor
IETF-compliant RFC 2822 timestamps
This question already has answers here:
How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift?
(13 answers)
Closed 2 years ago.
I am working in Swift language. I don't know the date format for this 2020-07-23T00:17:06.000Z.
I want to convert Date to String by following that format & vice versa.
How can I do? Thanks in advance...
it is iso8601
let string = "2020-07-23T00:17:06.000Z"
let dateFormatter = ISO8601DateFormatter()
dateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let date = dateFormatter.date(from: string)
I have a mysql DB and the dates are stored in it using the sql format of yyyy-MM-dd
I am using Jcalender for gui to get my customers DOB in java swing.
How do I use it to calculate the age of the person using yearsBetween() in joda time and then convert it to an int.
Please help, a code will be really useful :)
Okay I will post the code which is causing the problem
String dob = "1965-02-03";
DateTime today = new DateTime(DateTime.now().toLocalDate().toString());
DateTime start = new DateTime(dob);
System.out.println(today);
System.out.println(dob);
Years y= Years.yearsBetween(start, today);
System.out.println(y);
why does the y return a value of P485 instead of the correct value?
Your SysOut over class Years is missing a "getYears( )".
The code should be like this:
final String dob = "1965-02-03";
final DateTime today = LocalTime.now().toDateTimeToday();
final DateTime start = DateTime.parse(dob);
System.out.println(today);
System.out.println(dob);
final Years y = Years.yearsBetween(start, today);
System.out.println(y.getYears());