I need to convert a date type:
13/09/2014 19:20:32
13: day, 9: month, 2014:year, 19 hours, 20:minutes, 32:second
I used this code:
Dim data_convert As Date = Date.ParseExact(data_decripted, "dd/MM/yyyy hh/mm/ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
but tells me that the string is not recognized as a valid datetime value. How is this possible?
Am not a vb.net developer.After searching ur requirement i have found this.
You would need to use Date.ParseExact.
Dim edate = "dd/mm/yyyy"
Dim expenddt As Date = Date.ParseExact(edate, "dd/MM/yyyy",
System.Globalization.DateTimeFormatInfo.InvariantInfo)
Hope this helps..
Related
I am getting date from a server as a unix timestamp, how can I convert it to ISO 8601 date format in flutter?
the date I receive:
1611694800000
How I want to convert it to be
2021-01-26T22:00:00.000+00:00
What I have done so far with no luck
String s = '1611694800000';
debugPrint("Recevied date is: $s");
String dateS = DateTime.parse(s).toIso8601String();
debugPrint("Converted date : $dateS");
String dateStr = (dateS.split(".")[0].split("T")[0] + " 00:00:00").substring(1);
debugPrint("Activation date: $dateStr");
I end up getting:
Unhandled Exception: FormatException: Invalid date format.
Use DateTime.fromMillisecondsSinceEpoch:
var timestampMilliseconds = 1611694800000;
var datetime =
DateTime.fromMillisecondsSinceEpoch(timestampMilliseconds, isUtc: true);
print(datetime.toIso8601String()); // Prints: 2021-01-26T21:00:00.000Z
(Note that the printed time is one hour off of your stated expectation, but I'm assuming that's a mistake in your expectation.)
The reason why you are getting invalid date format is because you have to provide date in string like '2021-04-19' and not milliseconds;
This package makes it easy to format dates time_formatter
I am trying to update some code to use Java 8's feature for parsing multiple date formats. my local time on my box is set to UTC-11.
the below code works when using the SimpleDateformat.
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date correctDate = dateFormat.parse("2018-09-6T03:28:59.039-04:00");
//Gives me correct date
System.println( correctDate);//Wed Sep 5th 20:28:59 GMT-11:00 2018
I am trying to update this code to give the same date as above with the DateTimeFormatter in Java 8 , so i can handle another date format..
DateTimeFormattter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]XXX");
LocalDateTime updateDate = LocalDateTime.parse( "2018-09-6T03:28:59.039-04:00", dtf);
//shows the wrong date of 2018-09-06 03:28:59.039.
System.out.println( updateDate.toString() );// 2018-09-06 03:28:59.039
[solved]
I was able to fix this by using ZonedDateTime.
ZonedDateTime zdt = ZonedDateTime.parse("2018-09-6T03:28:59.039-04:00");
zonedDateTime = zdt.withZoneSameInstance(ZoneId.of("GMT"));
Date correctDate = Date.from( zonedDateTime.toInstance());
//correctDate is what i wanted Wed Sep 5th 20:28:59 GMT-11:00 2018
As soon as you parse your date string into a LocalDateTime the zone offset is lost because LocalDateTime does not hold any time zone or offset information.
When you format the LocalDateTime to a string again, you'll only have the time as it was parsed without offset.
The Documentation of LocalDateTime clearly explains this:
This class does not store or represent a time-zone. Instead, it is a description of the date, as used for birthdays, combined with the local time as seen on a wall clock. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.
You should consider using OffsetDateTime or ZonedDateTime.
Solved, using OffsetDateTime as suggested in the accepted 'Answer':
OffsetDateTime odt = OffsetDateTime.parse("2018-09-6T03:28:59.039-04:00");
Date correctDate = Date.from( odt.toInstant());
I am creating a function that convert octal to decimal to date. I already do the part of convert octal to decimal to date but i cannot get the format yyyy-mm-dd. Here is my code:
Public Function OctToDate(ByVal OctDate As String) As String
Dim LDate As Long
Dim ODate As String
Dim StrDate As String
Dim PlainDate As Date
ODate = OctDate
LDate = CLng("&O" & ODate)
StrDate = CDate(Format(LDate, "####/##/##"))
PlainDate = Format(StrDate, "yyyy-mm-dd")
MsgBox (PlainDate)
End Function
But the result that i always get is 10/15/2017 and the result that i want is 2017-10-15 can anyone help me? im stuck
The answer is about data type
Before:
Dim PlainDate As Date
After:
Dim PlainDate As String
I declare PlainDate as date but the Format returns strings thats why it does not change the format. Thank you for helping me
Here is the answer with the code sample::
https://msdn.microsoft.com/en-us/library/aa241719(v=vs.60).aspx
I hope help you.
I have problem i try set the default date is today end disable day passed.
But when i set the default date is today i must convert date to string. So i can't calculator this.
Some body help me set the default date is today and calculator date. Thanks for reading my topic!
This is my code:
this.startDate = new Date().toISOString();
this.minDate = new Date().toISOString();
<ion-datetime
displayFormat="MMM DD, YYYY HH:mm"
[min]="minDate"
[(ngModel)]="startDate"
>
</ion-datetime>
From ionicv2 docs
https://ionicframework.com/docs/api/components/datetime/DateTime/
Ionic uses the ISO 8601 datetime format for its value. The value is
simply a string, rather than using JavaScript's Date object.
Additionally, when using the ISO datetime format, it makes it easier
to serialize and pass within JSON objects, and sending databases a
standardized format which it can be easily parsed if need be.
So, you can get the ISO string date by
startDate: String = new Date().toISOString();
and use it in the view like so
<ion-datetime
displayFormat="MMM DD, YYYY HH:mm"
[(ngModel)]="startDate"
>
If you want to disable backdated date, you can try this
min="2016-10-31"
and also you can specify the maxDate by
max="2020-12-12"
in your ion-datetime directive
I have the code below for a pop up box asking for a date Ex: 4/5/2013, how do I automatically convert it to a Long date format?
I tried
strUserResponse = FormatDateTime(Date, vbLongDate)
But it is just giving me today's date
Thanks
Public Function AskForDeadline() As String
Dim strUserResponse As String
strUserResponse = InputBox("Enter attribute_5: Survey Deadline - In Short Date Format Ex: 4/9/2012 Will convert to LOND date AUTOMATICALLY")
strUserResponse = FormatDateTime(Date, vbLongDate)
ActiveSheet.Cells(2, 9).Value = strUserResponse 'the 2, 9 is the cell reference for I2 - row 2, column 9.
End Function
As I mentioned in your previous post that Inputbox is not the best way to get a date but if you still want to go ahead with this then change
strUserResponse = FormatDateTime(Date, vbLongDate)
to
strUserResponse = FormatDateTime(strUserResponse, vbLongDate)
You are getting the current date because you are converting Date in that line of code which will give you today's date.