3

How do I get the system time using VB.NET and copy it into the clipboard automatically?

Is there a built-in function in VB.NET for this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user225269
  • 10,743
  • 69
  • 174
  • 251

3 Answers3

5

I'm not sure what you mean by System Time, but if it's just the string representation of the current time then you can do the following.

ClipBoard.SetText(DateTime.Now.ToString())

This code will work in both Windows Forms and WPF.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • isn't it possible to just copy the time? – user225269 Feb 19 '10 at 09:23
  • `ClipBoard.SetText(DateTime.Now.ToString("HH:mm:ss"))` Alter the format specifier to customize the appearance if you like http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx – MarkJ Feb 19 '10 at 09:37
0

Use DateTime.Now to get the time and Google for the code to copy to the clipboard.

Or take a look at this post.

Community
  • 1
  • 1
Gerrie Schenck
  • 22,148
  • 20
  • 68
  • 95
0

Better use the DateTime.UtcNow method. It returns time without local format and DST offset.

UTC will keep you out of trouble when storing data. You can always format to local when export/display is needed.

Rahul Gupta
  • 9,775
  • 7
  • 56
  • 69
GiPo
  • 1