VB.Net Date String Format Patterns - vb.net

DateTime.Now to Jul 31 10:20:30 PST 2012 format
DirectCast(row(0), DateTime).ToString("ddd MMM dd HH:mm:ss 'PST' yyyy")
row(0) is a string that is in the format 7/29/2012 1:25:20 PM
Keeps telling me the cast is incorrect, how can I correctly cast the string?
Awesome link for patterns for datetime.

You should be using DateTime.Parse, DateTime.TryParse, DateTime.ParseExact or DateTime.TryParseExact.
I suspect you could use CType instead of DirectCast, but personally I'd go for the method call - it makes it clearer what you're doing.

Related

jqwidgets-datetimeinput date format d MMMM yyyy not displayed correctly

I am using jqwidgets-datetimeinput to display and input formatted date. It is working fine for most of the use cases but for the format d MMMM yyyy it is not behaving correctly.
it is showing as 6/11/2020 June 2020 instead of 11 June 2020
Interesting. I think you just found one of the many bugs/"features" that plague jqWidgets.
Upon further investigation, this seems to happen when d is the end of the format string, or is followed by a space character. To get around this, you can use a non-breaking space:
'd\u00a0MMMM yyyy'
If you're on Windows, you can also do Alt+0160 to type it out, but this may be unwise, as the two characters look identical.

Exception while try Date.ParseExact in VB.NET

I'm trying to parse this:
Date.ParseExact("5/19/2012", "M/d/yyyy", myCultureInfo)
In the machine with system date format MM/dd/yyyy, it works fine. But in machine with system date format dd-MMM-yyyy or any date format other than MM/dd/yyyy, it throws exception String was not recognized as a valid DateTime.. So how can I get my code above works regardless to system date format?
I found the solution
Date.ParseExact("5/19/2012", "M/d/yyyy", new Globolization.CultureInfo("en-GB")).toString(myCultureInfo)

Format a Date Time to the Full date/time pattern (short time) in Orchard

Within Orchard CMS (version 1.6) I have a Query that displays a DateTime property called StartDate. When setting it up I chose the "Full date/time pattern (short time)" as the Date format, and then I was rewriting the output as follows:
<My html text here> {Text}
This would render as "My html text here Saturday, April 13, 2013 2:30 PM".
I realized that for users on a different time zone, the date/time was being converted automatically and instead of displaying 2:30 PM (server is at PST), it was displaying 5:30 PM (user was at EST).
Following Bertrand Le Roy's solution here, it worked out nice with one minor issue.
Now my code is this:
<My html text here> {Content.Fields.MyContentType.MyDateTimeField.DateTime.Local}
And here is the result: "My html text here 4/13/2013 2:30:00 PM".
The formatting is not the one I would rather use.
Does anyone know how can I format this to the Full date/time pattern (short time)?
Thank you in advance.
{Content.Fields.MyContentType.MyDateTimeField.DateTime.Local.Format:dddd, MMMM d, yyyy h:mm tt} should do the trick.

VB 2010 Convert UTC Date to dd-MMM-yyyy format

I get the UTC Date and Time using:
Dim UTCN As Date = (Date.UtcNow)
It outputs 8/19/2012 3:48:24 PM
I need to FTP a file that must use the format dd-MMM-yyyy (19-Aug-2012)
My problem is that I must use UTC and it must be in the above format. This will run in various time zones so I do not want to use a fixed offset to convert local to UTC. I know how to FTP and everything else but I can not figure out how can I format UTCM to meet my needs?
Date.UtcNow.ToString("dd-MMM-yyyy")

Need to parse a string to date without padded 0's

I've read through a lot of examples, but the problem I'm facing is the date I'm getting doesn't have leading 0's and all the objective-c stuff I've found has them. So I need to take the date:
4/9/2012 1:30 PM
And determine if it is today. My place was to either grab today's date and compare it to the first part of that string, but as I said before I can't find anyway to make a date in objective c without leading 0's. I'm hoping to avoid parsing that string manually to add leading 0's.
Use an NSDateFormatter object
[dateFormatter setDateFormat:#"h:mm a"];
if you want 0's
[dateFormatter setDateFormat:#"hh:mm a"];
I think that using the single M option for your date format string will allow it to parse a single digit month value:
The possible date formats are specified here
#ynistersix answer is correct. In Data Formatting Guide, they said that NSDateFormatter follows http://unicode.org/reports/tr35/tr35-dates.html
h 1..2 11 Hour [1-12]. When used in skeleton data or in a skeleton
passed in an API for flexible date pattern generation, it should match
the 12-hour-cycle format preferred by the locale (h or K); it should
not match a 24-hour-cycle format (H or k). Use hh for zero padding.
This is consistent with most other languages. Like .NET
"h" The hour, using a 12-hour clock from 1 to 12.
2009-06-15T01:45:30 -> 1
2009-06-15T13:45:30 -> 1
"hh" The hour, using a 12-hour clock from 01 to 12.
2009-06-15T01:45:30 -> 01
2009-06-15T13:45:30 -> 01