|
[edit]I'm using .NET 1.1[/edit]
I have a date in the form of a string, in the American format, MM/DD/YYYY. How can I create a DateTime object from this string, irrespective of the current culture?
In other words, even if the current culture is French, the incoming string 11/03/2005 should be interpreted as Nov 03, 2005. I want to do this without changing the current culture.
I tried doing
DateTime suspDt = Convert.ToDateTime(strDate, new CultureInfo("en-US")); but that didn't work.
Thanks in advance!
Cheers,
Vikram.
"I am not Jesus and will never be. The fact is I was a piece of cr*p till I found Him." - Paul Selormey.
-- modified at 9:09 Tuesday 4th July, 2006
|
|
|
|
|
DateTime mydatetime = DateTime.Parse("11/03/2005");
|
|
|
|
|
Hi,
Try something like:
DateTime myDateTime = new DateTime(year,month,day);
The year,month and day can be substracted from the string if you know their exact position, using Substring and IndexOf. It helped me a lot sometimes. Hope it helps you.
Do your best to be the best
|
|
|
|
|
I was hoping there's a cleaner solution, but hey, your suggestion works.
Thanks a ton!
š
Cheers,
Vikram.
"I am not Jesus and will never be. The fact is I was a piece of cr*p till I found Him." - Paul Selormey.
|
|
|
|
|
Using .NET 1.1 and the following code:
string theDate = "11/03/2005";<br />
DateTime dt = Convert.ToDateTime(theDate, new System.Globalization.CultureInfo("en-US"));<br />
MessageBox.Show(dt.ToLongDateString());
Shows Nov 3 2005.
If I remove the culture info, and allow my local machine (UK) to decide, it gives March 11th. So basically that is exactly the desired behaviour!
What did you mean by:
Vikram A Punathambekar wrote: but that didn't work
It appears to work perfectly!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
J4amieC wrote: It appears to work perfectly!
I use the European format on my machine too, but it didn't work.
However, since then, I replaced the code with the DateTime(year, month, date) suggestion above and it works perfectly.
Thanks anyway!
š
Cheers,
Vikram.
"I am not Jesus and will never be. The fact is I was a piece of cr*p till I found Him." - Paul Selormey.
|
|
|
|
|
The magic word here is "appears", as you actually made a quite classic I18N error here. Don't worry, you are not the first one - and it won't fail on that many systems. What you really want to do is this:
new System.Globalization.CultureInfo("en-US", false);
Specifying "false" makes sure that you get the default en-US settings ignoring any changes done in the regional settings. Notice that if you do not run en-US regional settings you will always get the default - the potential problem is only for accounts configured with en-US settings and a changed date format.
|
|
|
|
|
|
Hi Folks,
i have a problem with common dialog', I need to open a file when i click the item from listbox. now i got open dialog with specified path but it dont open the file. can you plz give idea to solve this.
my code is here.,
the following code in selected index changed event for thet listbox.
OpenDialog.FileName="Filepath";
OpenDialog.OpenFile();
OpenDialog.ShowDialog();
ranandbe
|
|
|
|
|
??? I don't understand your code and what do you want to do with that, but normally I use it like this:
OpenFileDialog openFileDialog = new OpenFileDialog();
DialogResult dialogResult = openFileDialog.ShowDialog();
if(dialogResult == DialogResult.OK && openFileDialog.FileName != "")
{
} or
OpenFileDialog openFileDialog = new OpenFileDialog();
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream filestream = openFileDialog.OpenFile();
filestream.Close();
}
Before ShowDialog() you can only set the property like Path, Filter, etc...
Then you must call ShowDialog() to show the dialog. If the user select a file and click OK, then
you get a return value DialogResult.OK. Then you can get the filename by calling openFileDialog.FileName.
|
|
|
|
|
I am generating an Excel workbook from within a C# console app and wish to duplicate a worksheet which includes a pivottable. This however does not create a new pivotcache, so when the original worksheet is updated, the second is as well.
Does anyone know how I can separate the caches after they have been created? It is easy to link the new pivottable's pivotcache to a third pivotcache, but creating a new pivotcache without actually setting up a new pivottable seems impossible.
Thanks.
|
|
|
|
|
how can i read data about product from barcode and stoe it in data base
i hope an example becuase i am not profisional
then you for help
MD_NADA
|
|
|
|
|
Search CodeProject on the keyword "barcode" and you'll find articles that show how to work with barcodes.
:josh:
My WPF Blog[^]
|
|
|
|
|
How to add Application.config file for windows application project and how to access data from the file
Jey
|
|
|
|
|
Just select Add/New item (or something semantically equivalent - I don't have an english VS at hand) in your project and select Application configuration file. You'll get a file named "App.config" which is renamed to <YourExecutableName>.exe.config and copied to your output directory.
To access entries in the file you should take a look at the System.Configuration namespace.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
I'm trying to display my desktop icon's in a listview with a transparant background. I want the icons to be perfectly visible and the white background color to blend in with the graphics below the form.
So actually setting ListView.BackColor to transparant would do the trick. But ListView.BackColor doesn't support transparancy.
Is there an other 'listview' component that does support transparancy, or any other way to achieve a transparant background below the icons?
Cheers, Richard
|
|
|
|
|
You'll have to set a certain color as the BackColor of your ListView (I usually take magenta or cyan for this purpose) and then set the TransparencyKey of the Form containing your ListView to the same color.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Okay great, that worked. But now it's like there's no background at all.
Is there a way to make it semi transparant?
I tried to make a custom color with a alpha value of say 20, but then the listview complains again about not supporting transparant colors...
|
|
|
|
|
To achieve semi-transparency, you'll have to dig deeper into layered windows. But beware, that's not a trivial task and only has very limited support within .NET. YOu'll have to use lots of p/invoke calls to get layered windows working right.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hi
I am using following code to Import data from Excel File in .NET 2005
DataSet myDataSet = new DataSet();
string strConn = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = c:\test.xls;Jet OLEDB:Engine Type=5; Extended Properties=Excel 9.0";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter addapter = new OleDbDataAdapter();
addapter.SelectCommand = new OleDbCommand("Select * From Mercury$", conn);
addapter.Fill(myDataSet);
On Executing it is giving me Following error
"Could not find installable ISAM."
I am using Excel2003 installed on Windows 2000.
Thanks in advance
Abhi
|
|
|
|
|
Try this
Extended Property="""Excel 9.0"""".
i guess that works for u.
Regards,
Pramod
|
|
|
|
|
|
Hi,
How can i count the total number of rows and columns in the List View, is there any properties or methods with out using loops.
|
|
|
|
|
Hi,
there are some properties that can be used to obtain the number of columns and rows:
Columns:
MyListView.Columns.Count
Rows:
MyListView.Items.Count
Regards
Sebastian
|
|
|
|
|
Ofcourse i want to get the currently selected row and column is it possible if so how to do it?
-- modified at 9:07 Tuesday 4th July, 2006
|
|
|
|