I’m trying to convert a ISO timestamp into a UNIX timestamp to test this converted value with the current value.
The date is 2018-02-15T00:33:02.000Z
Can this be converted into a UNIX timestamp within Postman?
Thanks in advance.
You can convert this time in Postman using moment.js which comes with the native application.
var moment = require("moment")
console.log(moment("2018-02-15T00:33:02.000Z").valueOf())
This would convert the value and print it on the Postman Console if you add this to the pre-request script or Tests tab.
This is always a good site for cross checking: http://currentmillis.com/
The same could be done in native JavaScript but moment makes it much easier.
The question is very vague as to what you are trying to do but this is a basic answer.
Related
I am using grails 2.5.5 with java 8. To get this working with the new dates, I defined a mapping between the java 8 dates (ZonedDateTime) and the database/hibernate dates. This works fine, no problem at all
here's where the problem starts: Unit Testing:
I have a method which uses
Foo.withCriteria{
ge("startDate",foo.startDate)
}
the problem now is that startDate is a ZonedDateTime and I get the error that startDate is no existent property of Foo. Using FindAllBy gives the same problem.
I cannot mock this method, for it is a private method. How do i get these java 8 dates working in unit tests?
(if I gave too little information, just ask, I can provide, but I thought this would be enough and I wanted to keep it as general as possible for stackOverflow)
Each date has a different format so you must check that the Date are of the same type and format. Your Java 8 probably using java.util.Date and SimpleDateFormatter.
Please check your unit testing framework date format, it might be DateTime format so it causes the differences and may cause you error.
On the following code:
Foo.withCriteria{
ge("startDate",foo.startDate)
}
Make sure that the foo.startDate was initialized correctly using your unit testing framework with the correct format.
You can also use other date formats such as:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date convertedCurrentDate = sdf.parse(currentDateText);
or ISO 8601 DateTime Format
These are very popular formats using databases, which can explain why
Using FindAllBy gives the same problem.
I am recently trying to change our company's old program. One of the huge rocks in my way is that the old program was made with Borland C++, and it had its own way of connecting to the SQL Server 2000 database.
After 8 years, I'm trying to retire this program. But when I looked at the database, I got freaked out!
The whole database was in a vague language that was supposed to be Persian.
I'll give you a portion of the database converted to SQL Server 2005, so you can see it for yourself. I've spent many days trying to figure out how to decode this data. But so far no results has come out of it.
Link to the sample Database File
So please if you can tell me how to use them in Microsoft C#.net it will be much appreciated.
These are the datatypes used for them:
And this is how it looks:
Thanks a lot.
1) Analyse existing program and original database
Try to figure out how the C++ program stored Persian text in the database. What are the collations defined on the original server, database, and on column level.
Does the C++ program convert the data to be stored and retrieved from the database? If so, find out how.
It may well be that the program displays data in Persian, but does not store it in a compatible way. Or it uses a custom font that supports custom encoding. All this needs to be analyzed.
2) The screen shots looks as if everything Persian is encoded as ASCII characters higher than CHAR(128).
If this a standardized encoding or custom created?
3) To migrate the database, you most likely will need to convert the data mapping original characters to Unicode characters.
First recreate the tables using Unicode-enabled columns (NVARCHAR, NVARCHAR(MAX)) rather than CHAR and VARCHAR, which only support Latin or Extended Latin.
4) Even if you successfully migrated your data, SSMS may not correctly display the stored data due to font settings or OS support.
I summarized the difficulties of displaying Unicode in SSMS on my blog.
But first, you need to investigate the original database and application.
I want to develop a small application to get stock price from Google Finance automatically and store it in my local machine for future analysis.
Can anyone give me some clue how to get started?
I know some C#. Will it be suitable for this purpose?
Thank you in advance.
The Google Finance Gadget API has been officially deprecated since October 2012, but as of April 2014, it's still active:
http://www.google.com/finance/info?q=NASDAQ:ADBE
Note that if your application is for public consumption, using the Google Finance API is against Google's terms of service.
This gives a JSON response which can be parsed using a simple JSON parser in C# after chopping off the first two chars ('//').
For downloading historic data again, you could use the Google APIs.
http://www.google.com/finance/historical?q=NASDAQ:ADBE&startdate=Jan+01%2C+2009&enddate=Aug+2%2C+2012&output=csv
gives out a CSV of end of day stock prices from startdate to enddate. Use a simple CSV parser to get meaningful data out of this stored on your db. However, this format=csv option does not work for a few stock exchanges.
If you want to download historical data you can use the Google Finance API (which still works as of May 2016). You do not have to provide an end date, it will automatically fetch data from the start date (or later if the stock did not trade then) to the last full trade date:
http://www.google.com/finance/historical?q=NASDAQ:AAPL&startdate=Jan+01%2C+2000&output=csv
Remember that Google Finance API are for personal consumption ONLY. I suggest you their terms of service.
If you want to simply download the latest date (which could be useful to update your local db) you can use the googlefinance library developed by Hongtao Cai:
https://pypi.python.org/pypi/googlefinance
I have just implemented this with PHP. It might be useful.
<?php
echo readGoogle('AAPL', 'Aug+21%2C+2017', 'Aug+22%2C+2017');
function readGoogle($ticker, $startDate, $endDate) {
$fp = fopen("http://finance.google.com/finance/historical?q=".$ticker."&startdate=".$startDate."&enddate=".$endDate."&output=csv", 'r');
if (FALSE === $fp) return 'Can not open data.';
$buffer = '';
while (!feof($fp)) $buffer .= implode(',', (array)fgetcsv($fp, 5000));
fclose($fp);
return $buffer;
}
?>
I wan't to manage the different timezones of my users in my web application, but I have no idea where to start. I have to save the local time of each user in my database?, or maybe make the conversion to a UTC time, save it, and then make the conversion again to show it?, or there is another way? For example, if one of my users make an appointment in his local time, I have to convert it to UTC store it in my database, and then when he need it, convert it again to his local time an show it?? By the way, I'm using Django. Thanks.
Store date/time as UTC (Not sure what the Python command for that is)
When outputting dates, wrap them in a helper function that gets the current user's time zone preference, then adjust the time/date for the offset, then output it from the application.
http://docs.python.org/library/time.html
http://docs.python.org/library/datetime.html
Try the Django snippit UTC DateTime field. It has everything you'll need right out of the box, practically.
make the conversion to a UTC time, save it, and then make the conversion again to show it?
Yes, even if you only have one local timezone, you should generally be storing your dates as UTC timestamps in the database, and converting it to and from text in the appropriate timezone in your webapps input and output stages. When you have a per-user timezone stored it's then easy to switch out the default timezone for the customised one.
pytz is the usual solution for selecting and converting timezones. (Although personally I hacked up my own less overwhelming collection of timezones.)
Using a single "database time" timezone is, IMO, the best options because:-
It greatly simplifies routines for dealing with people in different timezones
It allows for easier conversions to other timezones
Anyone seeing the data out of context of the user's view can assume that it's UTC, and not have to guess if "12:45" for one record is "12:45" for another
Standards are good
So, yes. Store the user's timezone in the database, then store all times in a common time (Like UTC). Convert them when the user views anything including time. It's the simplest solution that doesn't just force all users to pretend to be in the same timezone.
The GetVersions() call to the Versions.asmx web service in SharePoint 2003 returns a localised date format, with no way of determining what the format is. It's the site regional setting of date format, but I can't find a way to get even that out of SharePoint 2003. Locally, it looks like SPRegionalSettings can be used (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spregionalsettings.aspx) but what about a web service version of this?
Sadly, it isn't available. However, you can specify a query option to specify that you want the values returned in UTC:
http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx
Unfortunately, the parameter that asks for the values in UTC is not supported for this call. I've just had to look for a month greater than 12 and use that as the hint to switch date formats. It'll mess up some dates, but I can't see a way around that. The code is at http://sourceforge.net/projects/splistcp/ if anyone is interested.