473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unixtime problem

Hello.

I have a task to develop a calendar in C#, therefore - I need to use unixtime I think.

But I don't know how to, can some one explain to me how to convert the date of today to unix time? And how can I add a day to the unixtime of today for example.

Thx guys.
Jul 1 '07 #1
2 1475
Wing
28
I found the unix portion of the code at the following link.

http://www.codeproject.com/csharp/timestamp.asp

Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : Form
  2.     {
  3.         public Form1()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         private void Form1_Load(object sender, EventArgs e)
  9.         {
  10.             DateTime cDate = DateTime.Now;
  11.             label1.Text = "Current Date and Time: " + cDate;
  12.             label2.Text = "Current Unix Time: " + getUnixTimeStamp(cDate);
  13.             DateTime tmpDate = cDate.AddDays(1);
  14.             label3.Text = "Current Unix Time plus 1 day: " + getUnixTimeStamp(tmpDate);
  15.         }
  16.  
  17.         public static long getUnixTimeStamp(System.DateTime date_time_convert)
  18.         {
  19.             DateTime date_time_base = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  20.  
  21.             TimeSpan span = date_time_convert.ToUniversalTime() - date_time_base;
  22.  
  23.             return (long)span.TotalSeconds;
  24.         }
  25.     }
Jul 1 '07 #2
Wow, thank you!
It is very helpful.
Jul 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Sandman | last post by:
Hi. On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with PHP. That is, when feeding a function that turns dfates into unixtime, such as mktime() and strtotime() print...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
0
by: Dan | last post by:
I'am having problem with the SQL statement... MySql Database Table structure for phpnews_news is id int unsigned auto_increment primary key, posterid int, postername char(40), time int, etc...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: _mario.lat | last post by:
Hallo, I have to calculate difference in seconds between two timestamp (unixtime). the problem is when there is daylight saving time so in this case end-start shoultd be negative and wrong data....
1
by: smitanaik | last post by:
hi i have unixtime format 1075329297.572 how do i store it in database.that is with what datatype.i tried to store unixtime using date, timestamp but it does not work. but with varchar2 it works....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.