|
|
i have a informix database
|
|
|
|
|
That little gem of information may have been useful in your original post!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi ALL,
My requirement is very simple.
I have one string in "HH:MM" format.
Want to store same in DateTime format but same in HH:MM format
example :-
string str1 = "21:56";
DateTime Date = Convert.ToDateTime(str1);
Now we have to store this value in XML and which takes input as DateTime object.. and in xml it should display pnly in HH::MM format
<filetime>21:56
I am unable to find solution for it
Tried couple of options but its not working
please help me
|
|
|
|
|
not quite sure what you're asking for
if you have this (as per your example)
DateTime Date = Convert.ToDateTime(str1);
then you can do this
String dateAsString = Date.ToString("hh:mm");
(12hr format, or use "HH:MM" for 24hr format)
is that what you mean ?
|
|
|
|
|
Hi Garth,
Let me explain u in deeply.
I have one XSD, I have converted it to .cs format.
Now I have to generate XML by using this.
In XML I have one field as given below.
private System.DateTime transactionTimeField;
Now in this field I have to store Time value that also as given below
<transactiontime>02:12:00
I am trying but unable
Please let me know if you can help me here.
|
|
|
|
|
You can do that by using TimeSpan object. This will have only time in it.
For e.g :
TimeSpan ts = TimeSpan.Parse("12:15:06");
|
|
|
|
|
Thanks Praneet but TimeSpan I cant store in DateTime.
Please correct me If I am wrong.
I want to store HH::MM in DateTime object
|
|
|
|
|
so, what is wrong with
DateTime myTime = new DateTime(0,0,0,HH,MM,0);
or
dateString = "08:30";
format = "hh:mm";
try {
result = DateTime.ParseExact(dateString, format, provider);
Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException) {
Console.WriteLine("{0} is not in the correct format.", dateString);
}
(I cribbed that one from MS and hacked up the dateString and format)
|
|
|
|
|
Garth J Lancaster wrote: so, what is wrong with
DateTime myTime = new DateTime(0,0,0,HH,MM,0);
What, apart from "it won't work?"
You will get a System.ArgumentOutOfRangeException "Year, Month, and Day parameters describe an un-representable DateTime."
Your second example works - to an extent - but doesn't quite do what he wants as the Year, Month and Day parts of the DateTime will be set to DateTime.Now.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
hmph !!!
thanks OG - I thought you could just set the time component
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
No. You can't store "just the hours and minutes" in a DateTime: it requires a Year, Month and Day value which cannot be zeroed. So the best you can do is store the Hours and Minutes together with a sepecific date (And probably DateTime.MinValue would be best as DateTime.Now values are used if not specified).
Personally, I'd use a Timespan, or an integer value representing the seconds since midnight instead.
Using a DateTime implies a number of things which aren't necessarily true.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If you feel that DateTime is not working for you, nothing prevents you from writing a class that holds, validates and converts "time". Make sure it is as compliant as possible with the DateTime object.
|
|
|
|
|
bhausahebshedbale wrote: I have one string in "HH:MM" format.
Want to store same in DateTime format but same in HH:MM format
No. Don't do that.
A timestamp is a value that ALWAYS has a timezone either implicitly or explicitly.
If you have only a time then it is not a timestamp. Just that simple. Thus attempting to coerce it into a timestamp is at best difficult and worse will end up causing more problems than you think it will fix.
Create your own class and create the XML supporting classes/methods to support it as such.
|
|
|
|
|
Hello!
I have a PropertyGrid in an application displaying some properties in a class. One property has it's own TypeConverter to display an array of strings.
Issue
I would like to change the TypeConverter of the property in runtime.
Example
I have included a simple example code. You should be able to just paste the code in a Windows Forms Application, compile and run. Remember to create a PropertyGrid (propertyGrid1) and a button (button1) in the Form and add the button's click event.
Notice the two static string arrays in the Form1 class. These arrays are used with the TypeConverters NameList and SentenceList.
When the application start you will see the PropertyGrid displaying the name list in the property called Item. When you click the button I want the list of names to change to the list of sentences instead. I imagined the SwopList() method in the Props class should handle this. I call the SwopList() method with the button's click event.
In the SwopList() method I fetch the PropertyDescriptor object of the Item property. Then I can see what TypeConvert is used with the property PropertyDescriptor.Converter. From that point I just want to swop the TypeConverter (like the code I have commented out). But this don't work as PropertyDescriptor.Converter is read only
Any solution?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public static string[] Names = new string[] {"Jon Smith", "Fred Perry", "Foo Bar" };
public static string[] Sentences = new string[] { "Hi hello!", "Bye", "Peace and long life", "Live long and prosper" };
Props properties = new Props();
public Form1()
{
InitializeComponent();
propertyGrid1.SelectedObject = properties;
}
private void button1_Click(object sender, EventArgs e)
{
properties.SwopList();
propertyGrid1.Refresh();
}
}
public class Props
{
string name = Form1.Names[0];
string sentence = Form1.Sentences[0];
string item;
public Props()
{
item = name;
}
public void SwopList()
{
PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties(this);
PropertyDescriptor pd = pdc["Item"];
if (pd.Converter is NameList)
{
item = sentence;
}
else if (pd.Converter is SentenceList)
{
item = name;
}
}
[TypeConverter(typeof(NameList))]
public string Item
{
get { return item; }
set { item = value; }
}
}
public class NameList : TypeConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(Form1.Names);
}
}
public class SentenceList : TypeConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(Form1.Sentences);
}
}
}
Best regards,
/Steffe
|
|
|
|
|
Theoretically, you cannot change the value of the attribute during runtime; it is compiled. Hence, recompile and it would work. That would require unloading of the type, which is a little bit overkill.
Alternatively, you create a TypeConverter that works as a proxy, using either the implementation of NameList or SentenceList as the actual implementation.
Alternatively, you create two exact the same classes (different names though), decorate each with its own converter, and create a converter to kick the data from object1(class1) to object2(class2).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks!
I solved it by using your "proxy" suggestion
|
|
|
|
|
Cool
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Anyone knows good tool or open source tool for image based automation like i want to find any inout image on windows or web application and i need to do some automation on that image if it is able to find that image. I have an java applet form which i need to automate through c# tool i am not able to access its controls so i am going for image based automation which is required also. I looked at sikuli , aspire , auto-it and others but no where mentioned how it will be integrated in c# project.
Please help i just want like below :- i got one link but that too doesn't worked
http://www.youtube.com/watch?v=rF2G87b6qiQ
|
|
|
|
|
|
Thanks ...Any other option through which i can image based automation other than auto-it and sikuli
|
|
|
|
|
Renorex doing it but i want to find some open source . See i want like this :-
[^]
|
|
|
|
|
I'm not going to Google.
If you have a specific question, please ask.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yeah..Will autoit be helpful for me for my requirement..
|
|
|
|