0

I want to get day, month and year separately from unix timestamp in format decimal(16,4) which was written to MySQL database by Contact Form 7 to Database Extension Wordpress plugin.

I need to do it in JAVA!

For example, I want to parse 1379446159.0400 (2013-09-17 19:29:19 +00:00) but I don't have an idea how to do it.

Milos
  • 13
  • 5
  • 1
    Well what is that value meant to be? A number of seconds since the unix epoch? Something else? Do you know what timestamp that example is meant to represent? Are you trying to do this in Java or PHP? (It's unclear why you've got both tags...) – Jon Skeet Feb 10 '16 at 09:29
  • I wasn't sure what is generating this format so I tagged PHP but I am now more inclined to think i is Unix timestamp format. I just edited original question after I found time represented by that number. I am working in Java, Android app – Milos Feb 10 '16 at 09:41

3 Answers3

0

Hope this helps :

SELECT from_unixtime('1379446159.0400 ', '%Y %D %M %h:%i:%s') as time
Ralph John Galindo
  • 1,190
  • 6
  • 11
  • My PHP script is sending XML data to my Android application. I read the XML and I want to get day, month and year from this annoying decimal(16,4) using Java – Milos Feb 10 '16 at 09:35
  • If you are using php , [Check here](http://sandbox.onlinephpfunctions.com/code/50897904b815f73044aa84ac7fa0db2160f84a97) . That is the PHP code you can use. They way you return it as xml is another story. – Ralph John Galindo Feb 10 '16 at 09:40
0

If you ignore the fractional part of the peculiar timestamp then you can do:

$ds=1379446159.0400;
list( $ts,$junk )=explode( '.',$ds);

$year=date( 'Y', $ts );
$month=date( 'm', $ts);
$day=date( 'd', $ts );
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
0

Okay, thank you all for trying to help me despite my insufficiently specified question.

I found the solution here and implemented it like this:

long unixSeconds = Long.valueOf(submit_time.substring(0,10)).longValue();
Date date = new Date(unixSeconds*1000L);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String formattedDate = sdf.format(date);
String timestampYear = formattedDate.substring(1,4);
String timestampMonth = formattedDate.substring(6,7);
String timestampDay = formattedDate.substring(9,10);

So, I disregarded last four digits, guess it is legit enough.

Community
  • 1
  • 1
Milos
  • 13
  • 5