Epoch Time

Info.Tech, PHP, Software Development, Visual C# .Net, Web Development Comments Off on Epoch Time

I saved this information due to I used it all the time in my programming either PHP, JavaScript nor Visual C#. I found very very useful.. ๐Ÿ™‚


What is epoch time?

The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1-1-1970), but ‘epoch’ is often used as a synonym for ‘Unix time’. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).

Human readable time Seconds
1 minute 60 seconds
1 hour 3600 seconds
1 day 86400 seconds
1 week 604800 seconds
1 month (30.44 days) 2629743 seconds
1 year (365.24 days) 31556926 seconds

How to get the current epoch time in …

Perl time
PHP time()
Ruby Time.now (or Time.new). To display the epoch: Time.now.to_i
Python import time first, then time.time()
Java long epoch = System.currentTimeMillis()/1000;
Microsoft .NET C# epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
VBScript/ASP DateDiff("s", "01/01/1970 00:00:00", Now())
Erlang calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time( now()))-719528*24*3600.
MySQL SELECT unix_timestamp(now()) More information
PostgreSQL SELECT extract(epoch FROM now());
Oracle PL/SQL SELECT (SYSDATE - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) *
24 * 60 * 60 FROM DUAL
SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
JavaScript Math.round(new Date().getTime()/1000.0) getTime() returns time in milliseconds.
Unix/Linux Shell date +%s
PowerShell Get-Date -UFormat "%s" Produces: 1279152364.63599
Other OS’s Command line: perl -e "print time" (If Perl is installed on your system)

Convert from human readable date to epoch

Perl Use these Perl Epoch routines
PHP mktime(hour, minute, second, month, day, year) More information
Ruby Time.local(year, month, day, hour, minute, second, usec ) (or Time.gm for GMT/UTC input). To display add .to_i
Python import time first, then int(time.mktime(time.strptime('2000-01-01 12:34:00', '%Y-%m-%d %H:%M:%S'))) - time.timezone
Java long epoch = new java.text.SimpleDateFormat ("dd/MM/yyyy HH:mm:ss").parse("01/01/1970 01:00:00");
VBScript/ASP DateDiff("s", "01/01/1970 00:00:00", time field) More information
MySQL SELECT unix_timestamp(time) Time format: YYYY-MM-DD HH:MM:SS or YYMMDD or YYYYMMDD
More on using Epoch timestamps with MySQL
PostgreSQL SELECT extract(epoch FROM date('2000-01-01 12:34'));
With timestamp: SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-08');
With interval: SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', time field)
JavaScript use the JavaScript Date object
Unix/Linux Shell date +%s -d"Jan 1, 1980 00:00:01" Replace ‘-d’ with ‘-ud’ to input in GMT/UTC time.

Convert from epoch to human readable date

Perl Use these Perl Epoch routines
PHP date(output format, epoch); Output format example: ‘r’ = RFC 2822 date More information
Ruby Time.at(epoch)
Python import time first, then time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch)) Replace time.localtime with time.gmtime for GMT time. More information
Java String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000));
VBScript/ASP DateAdd("s", epoch, "01/01/1970 00:00:00") More information
MySQL from_unixtime(epoch, optional output format) The default output format is YYY-MM-DD HH:MM:SS more …
PostgreSQL PostgreSQL version 8.1 and higher: SELECT to_timestamp(epoch); More information Older versions: SELECT TIMESTAMP WITH TIME ZONE 'epoch' + epoch * INTERVAL '1 second';
SQL Server DATEADD(s, epoch, '1970-01-01 00:00:00')
Microsoft Excel =(A1 / 86400) + 25569 Format the result cell for date/time, the result will be in GMT time (A1 is the cell with the epoch number). For other timezones: =((A1 +/- timezone adjustment) / 86400) + 25569.
Crystal Reports DateAdd("s", {EpochTimeStampField}-14400, #1/1/1970 00:00:00#) -14400 used for Eastern Standard Time. See Timezones.
JavaScript use the JavaScript Date object
Unix/Linux Shell date -d @1190000000 Replace 1190000000 with your epoch, needs recent version of ‘date’. Replace ‘-d’ with ‘-ud’ for GMT/UTC time.
PowerShell Function get-epochDate ($epochDate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochDate)) }, then use: get-epochDate 1279152364. Works for Windows PowerShell v1 and v2
Other OS’s Command line: perl -e "print scalar(localtime(epoch))" (If Perl is installed) Replace ‘localtime’ with ‘gmtime’ for GMT/UTC time.


Reference: http://www.epochconverter.com

Prototype POS System – Transparent GUI

Info.Tech, Software Development, Visual C# .Net 2 Comments »

POS System – Transparent GUI

My article is about a prototype POS system for grocery stores or 24 hours mini marts using Transparency graphical user interface.

Transparency in MS Visual C# works similar to chroma keys in Adobe After Effects or Premiere. All you have to do is set a color key to make it transparent.

  1. As you create a form as Form1, go to Form1 properties and set TransparencyKey to Black.
  2. Then set your Backcolor of your form to Black.
  3. In Photoshop or any image editing tools, create an GUI or layout design then save as PNG format.
  4. In Form1 properties, set BackgroundImage and select the PNG image you created from Photoshop or other image editing tools.
  5. Set also the FormBorderStyle to None and Opacity to 95%.
  6. Then run your project. You’ll see the transparency works well. ๐Ÿ™‚

See my sample source code.

Prototype POS System - Transparent GUI (939)




Visual C#: Detect Conflict Schedule

Info.Tech, Software Development, Visual C# .Net 4 Comments »


It seems a lot of people are searching about solving conflict schedule. So I decided to create a sample. Below is the core code of checking conflict schedule…

// sample conflict detection (defined) [start]
DateTime d = new DateTime(2010, 1, 13);
richTextBox1.Text = DateTime.Now.ToLongDateString() + " = " + d.ToLongDateString() + "\n";
if (DateTime.Now.CompareTo(d) > 0)
richTextBox1.Text += "true\n" + DateTime.Now.CompareTo(d).ToString();
richTextBox1.Text += "false\n" + DateTime.Now.CompareTo(d).ToString();
richTextBox1.Text += "\n\n";
DateTime dx = DateTime.Now;
DateTime[] dt = new DateTime[4];
// enrolled schedule
dt[0] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 8, 0, 0);
dt[1] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 9, 0, 0);
// adding new schedule
dt[2] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 9, 0, 0);
dt[3] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 10, 0, 0);
// checking schedule conflict
if (((dt[0].CompareTo(dt[2]) < 0) && (dt[1].CompareTo(dt[2]) > 0)) || (dt[0].ToShortTimeString() == dt[2].ToShortTimeString()))
richTextBox1.Text += dt[0].ToShortTimeString() + " - " + dt[1].ToShortTimeString() + " against " + dt[2].ToShortTimeString() + " - " + dt[3].ToShortTimeString() + "\nResult: CONFLICT";
richTextBox1.Text += dt[0].ToShortTimeString() + " - " + dt[1].ToShortTimeString() + " against " + dt[2].ToShortTimeString() + " - " + dt[3].ToShortTimeString() + "\nResult: NO CONFLICT";
// sample conflict detection (defined) [end]

If you want to download the whole code, link below and enjoy… Do not practice the copy and paste! ๐Ÿ™‚

Download: Detect Conflict Schedule (801)

Visual C#: Retrieving Image (BLOB) from MySQL database

Info.Tech, Software Development, Visual C# .Net Comments Off on Visual C#: Retrieving Image (BLOB) from MySQL database

I’ve been searching an article about storing and retrieving an image (BLOB data type) from MySQL database. Somehow, I only found the retrieving process but I created the storing process using PHP… ๐Ÿ™‚

You may download my works, link provided below…

  • idsystem_database.sql.zip – the dump file of MySQL database; import this SQL file before running the project
  • the rest of the files are the project sample files

-> retrieveImg_public.zip (1474) or http://blog.camilord.com/my.files/retrieveImg_public.zip

For the credits, Thanks to Markusek Peter…

MySqlConnection myConnection = new MySqlConnection(myConnString);

string testQuery = “SELECT sp.studePhoto, s.firstName, s.lastName

FROM students AS s, student_photos AS sp WHERE s.id = sp.studentID”;
MySqlCommand myCommand = new MySqlCommand(testQuery, myConnection);

MySqlDataReader myReader = myCommand.ExecuteReader();

FileStream fs; // Writes the BLOB to a file (*.jpg).

BinaryWriter bw; // Streams the BLOB to the FileStream object.

int bufferSize = 100; // Size of the BLOB buffer.

// The BLOB byte[] buffer to be filled by GetBytes.

byte[] outbyte = new byte[bufferSize];
long retval; // The bytes returned from GetBytes.
long startIndex = 0; // The starting position in the BLOB output.

while (myReader.Read())
DateTime tmp = new DateTime();
tmp = DateTime.Now;
// Create a file to hold the output.
string filename = camilordMD5(tmp.ToLongDateString().ToString() + tmp.ToLongTimeString().ToString()) + “.jpg”;

string dest = Directory.GetCurrentDirectory() + “/” + filename;
fs = new FileStream(dest, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);

// Reset the starting byte for the new BLOB.
startIndex = 0;
// Read the bytes into outbyte[] and retain the number of bytes returned.

//myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
retval =(long) myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
lblName.Text = myReader.GetString(1) + ” ” + myReader.GetString(2);

// Continue reading and writing while there are bytes beyond the size of the buffer.
while (retval == bufferSize)

// Reposition the start index to the end of the last buffer and fill thebuffer.
startIndex += bufferSize;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);


pictureBox1.ImageLocation = Directory.GetCurrentDirectory() + “/test.jpg”;
//pictureBox1.Image = retval;

// Write the remaining buffer.

bw.Write(outbyte, 0, (int)retval – 1);

// Close the output file.

Visual C#: Handling X button (top-right)

Info.Tech, Software Development, Visual C# .Net 1 Comment »

xbuttonDisabling the X button

private const int CP_NOCLOSE_BUTTON = 0x200;

protected override CreateParams CreateParams
        CreateParams myCp = base.CreateParams;
        myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
        return myCp;

Add confirmation if window closing or closed…

Insert this code to Main form or the Form1.cs

private void Form1_Closing(object sender,
                   System.ComponentModel.CancelEventArgs e)
     if (MessageBox.Show("Are you sure you want to exit?", "Confirm exit",
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
        e.Cancel = true;

Insert this to Form1.Designer.cs…

this.Closing += new System.ComponentModel.CancelEventHandler(

Visual C#: Connecting to MySQL remotely

Info.Tech, Software Development, Visual C# .Net 2 Comments »

I have a current project that connects to a remote database server using Visual C# as client window application. So before I started my project, I tested it if it is possible to connect and the result, it does connect. For those does who failed to solve this problem, here’s my tutorial/guide.

Test Project Requirements:

  • VMware Workstation 5.5
  • CentOS 4.4
  • Visual C# Express Edition
  • MySQL Data Connector .Net v1.0.7


The client’s OS is MS Windows XP and the server is CentOS Linux. The client will connect to the Linux server to query and process some transaction. But in the sample code, it demonstrate only how to connect remotely in the server. My server’s IP address is and a MySQL port of 3306 (default port).



Step 1:

Setup the Linux server, be sure you already installed MySQL server. In our case, we use VMware and a CentOS 4.4 is installed. For installation help, google it! ๐Ÿ˜› The first thing to do is configure your IP tables by using iptables command. see illustration below;


If your configuration does not allow foreign connection to your MySQL, then change that and allow it. In real scenario if your server is public, I recommend that you must have a new server which can only be access through local network. Or if cannot afford, just setup well the IP tables that only local connections are allowed. Anyway, here’s my new IP tables setup in my server;


In MySQL CLI, create a user that can access everywhere. To do this, see sample below;

mysql> GRANT ALL PRIVILEGES ON *.* to ‘beasaw’@’%’ IDENTIFIED BY ‘qwerty’;

Explained: the command shown above is to allow user, beasaw, to access anywhere using a password qwerty.

That’s it… server setup completed. ๐Ÿ˜€

Step 2:

Before you create a new project in VCS, test first the connection using the command;

C:\> mysql\bin\mysql –-host= –-port=3306 –-user=beasaw –-password=qwerty

See image below;


Step 3:

  1. Open your Visual C# and create a new project, name it to remoteMySQL.
  2. In Form1.cs, layout just like the screenshot above.
  3. Add a reference, MySql.Data.dll (assumed that you already installed the MySQL data connector .Net v1.0.7)
  4. Add mysql to the project: using MySql.Data.MySqlClient;
  5. Begin your codes, see sample code (download link below)… ๐Ÿ˜›


That’s it… You can create as many applications you want with this method. Like Ticketing System, connecting 10 terminals to the servers simultaneously and etc. And of course, connection varies also to your MySQL server setup. ๐Ÿ˜€


ยป VCS Remote Connect to MySQL Server (819)

[Software Integration] MS Visual C# + Nokia PC Connectivity API 3.2

Info.Tech, Software Development, Visual C# .Net 14 Comments »

I’m having curiosity about retrieving SMS from Phone to my PC and including sending SMS from PC via Mobile Phone as GSM modem. So I decide to research about it. And I found the Nokia PC Connectivity API. Somehow using the API needs an extensive knowledge of Programming in .Net studio. So if your beginner to Visual C#, try to study more before taking this step. ๐Ÿ™‚

Download Nokia PC Connectivity API 3.2 (1414)

Download PC Suite Connectivity API 1.1 (1026)

Whatโ€™s in the Nokia PC Connectivity API tool package?

The Nokia PC Connectivity API tool package contains the PC Connectivity API headers, API documentation, and sample applications. The latest version of the tool includes updates to the Device Management, File System, and Content Access APIs, as well as support for Microsoft Visual Studio 2008.

For more information, visit the Nokia PC Connectivity API features page ยป

All I can say about this new area since I’m a web developer, its like HELL! hahahahaa…

By the way, Nokia Connectivity API documentation is limited and no enough sample resources. There are very few samples or let me say no enough sample in the internet so far. That’s why its like hell. ๐Ÿ˜›



  1. http://www.codeproject.com/Articles/38705/Send-and-Read-SMS-through-a-GSM-Modem-using-AT-Com
  2. http://www.sourcecodester.com/visual-basic/sending-sms-using-commands-gsm-modemgsm-phone-receiving-sms-updated.html
  3. http://www.codeproject.com/Articles/19023/Sending-SMS-using-NET
  4. http://www.codeproject.com/Articles/20420/How-To-Send-and-Receive-SMS-using-GSM-Modem
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in